Forum Moderators: coopster
I'm kind of curious as to what is the performace effect(memory, server load, etc..) of multiple includes, say 30-50 include call.
I'm trying to script in PHP where...
the public PHP page(index.php, etc..) would contain a single PHP include statement -> <? include("path_script.inc")?>
where "path_script.inc" would contain the path to a library of functions -> /path/include_lib.inc
where "include_lib.inc" would further contain all the major class and other functions. Meaning, this file would be the master include file.
I'm new to PHP but not new to programming. Correct me if I'm wrong but it is my understanding that this kind of structure would load all the functions regardless if they are needed or not by the calling page.
Say, index.php would need functions 1-5 and doesn't need the rest of the library of functions. Say, page2.php would need functions 1,2,6 and different function needs for each public php page.
How would this effect your server load and memory allocation? Anybody have experience with this kind of situation.
Or, how would you structure your scripts in such a way that the public php pages don't have to call several include to different location of your scripts for security reason and ease of management?
Any input please?
Thanks
say 30-50 include call
seems like a lot but if you need it, you need it
I don't really understand the need to include path_script.inc and include_lib.inc if all path_script.inc is doing is to hgave the path to another file to include.
Here's the way I try to structure things.
I always have a config file which has to be included first.
Then I usually have a site wide include. These are the functions that are needed 99% of the time so they need to be included on every page.
I use include_once instead of include to be sure that libs aren't double included.
I then include in dividual libs, either, on each page or with a section based include for things needed there. I also just build my libs targetted to individual sections or related groups of processes.
How would this effect your server load and memory allocation?
there are no adverse effects because we benchmark everything and run multiple servers of our own that are real monsters. ;)
It does depend on your own individual setup. You also have always be aware of these things and, when designing and building, structure things accordingly. Would our system run on a smaller setup? No chance, but it shouldn't be put on a smaller setup either.
things to keep in mind
then all should be well
I aslo don't name any of my files .lib or .inc, it's always .lib.php or .inc.php then code can never be viewed in a browser if someone happens to know a filename.
I don't really understand the need to include path_script.inc and include_lib.inc if all path_script.inc is doing is to hgave the path to another file to include.
There's a need to separate scripts from contents. Scripts would be located to a directory that is only known to the administrator.
I then include in dividual libs, either, on each page or with a section based include for things needed there. I also just build my libs targetted to individual sections or related groups of processes.
So, for example if a page would need 3 functions then in your page, you would have 3 <? include("file")?> and 3 function calls <? function()?>. Right? Unfortunately, I couldn't do that.
I also don't name any of my files .lib or .inc, it's always .lib.php or .inc.php then code can never be viewed in a browser if someone happens to know a filename.
I agree with you, I don't know what I'm thinking, so used to naming files according to their function. :)
Thanks for the sound advice. I'll try to benchmark it and see if it has an adverse effect on a single server. Probably, I might end running it through an optimizer, hope not.
Cheers
So, for example if a page would need 3 functions then in your page, you would have 3 <? include("file")?> and 3 function calls <? function()?>.
not really, probably poor explanation on my part, sry.
say we have
db_funcs.lib
datetime.lib
form.lib
section2.lib
section7.lib
etc
The functions within these libs are grouped by function, sometimes split into 2 libs if it helps processing.
if there is no form I won't need the form.lib.
if I'm not in section7 I won't need it's lib
etc
Seems to make perfect sense but sometimes there are different lib breakdowns that make sense when in a web environment than in an offline software application.
I usually put all path information in the config script and then include from there. You may also see different performance impacts if you nest includes too much than if you just include them all right on the page.
Appreciate your help and I'll see if I can streamline my include calls.
Cheers
Thanks