Solved

Large php files

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now