Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Large php files

Posted on 2003-10-30
4
Medium Priority
?
231 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 450 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 150 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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

722 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