Solved

Large php files

Posted on 2003-10-30
4
224 Views
Last Modified: 2010-05-18
Hi,
Regarding performance, is it better to code in small PHP files or a few large PHP files in building a site.
I prefer to use a few large PHP files but I suspect that this might create memory (or other kind) problems.

Thank you.
Deniz.
0
Comment
Question by:deniz_ortak
4 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 150 total points
ID: 9648794
Depends a little on the situation.

If all lines are to be executed (no big if-then-else structures) then 1 big file is faster.

If you've got some big if-then-else structures, then it will be faster to store the code needed in those structures in other files and include those files.
That way the code you don't need isn't parsed, thus the end result is faster.


On my own site I've got about 4000 lines of PHP code, 1000 of those are in a main script wich includes other files when needed.
Those 1000 lines are allways needed, so I kept them in there, the 3000 other lines are not allways used and are only included when needed.

Get the idea?
0
 
LVL 11

Assisted Solution

by:shmert
shmert earned 50 total points
ID: 9651479
DoppyNL is exactly right.  It's just a question of balancing the cost of include()ing a new file with the cost of parsing unused code.

I have a bunch of lib files, which contain functions or classes for a certain area.  Then I use require_once('lib.network.php'); if I need some network function code.  Using require_once() instead of require() ensures that you won't get those "function xyz is already defined" errors.
0
 
LVL 3

Assisted Solution

by:red010knight
red010knight earned 50 total points
ID: 9655479
Another thing you might try if you have an excessive amount of HTML code in your php files, is using the
eval() function. You basically create an HTML template of your page. With various variables without all the:
 <?php ... ?> included in it.

And using a file naming scheme of index.php and tpl_index.html this will help you to keep it straight. And make redesigning your site a WHOLE lot easier. As you don't have to change the php code or work around it. Just make sure all your variables stay the same.

Just another tip that might help as well.

Good luck coding,
Red010Knight
0
 

Author Comment

by:deniz_ortak
ID: 9658280
Thank you for your   help

<b>Deniz</b>
<b>
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question