Solved

Large php files

Posted on 2003-10-30
4
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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