Page 1 of 1

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

Posted: Sat Jun 25, 2005 11:46 am
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

Posted: Sat Jun 25, 2005 2:01 pm
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.