Solved

Large php files

Posted on 2003-10-30
4
228 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 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