if i use include("file")....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adixtopix
Forum Newbie
Posts: 17
Joined: Thu Jun 23, 2005 7:02 am

if i use include("file")....

Post by adixtopix »

hello, i'm new to php so my question will appear dumb for others

i have a function in one php file, another function in another file and so on

i am doing something like
include("1.php");
include("2.php");
include("3.php");
include("4.php");
include("5.php");

what i mean to ask is if my page will load slower if i use so many include calls
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Premature optimization is the root of all evil.

That being said, you should make your includes based on what makes sense to you, and then worry about the overhead of calling many include files. For instance, it's good practice to put all class definitions in their own files. For some projects, that means 50 or so includes every page request. Having one include for every function seems a bit excessive to me, but if you group functions together logically you can probably still end up with 2 or so includes.

But the truth is, yeah, there is an overhead to including lots of PHP files. Functions, I'd suggest minimizing the impact by putting them all in one file. But don't start stripping out all the includes in your script: after all, Premature optimization is the root of all evil. When you finish your script, and benchmark it, focus on the parts that take up the most processing time. If it is includes, try trimming the include tree. If it's something else, don't worry about the includes.
Post Reply