Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best use of include statement?

Status
Not open for further replies.

RbgoWeb

Programmer
Apr 10, 2002
91
NL
What is the best use of include statement?
When include a file from disk, the disk/file access time can be 10ms, while the datatransfers from file into memory can be > 500MB/sec. Is a function in an include file always parsed and compiled, or only when that function is used somewhere in the remainder of the code? If the latter is the case I will put all 20? functions in one big include, and will reduce include time from 20 x 10ms= 0.2 sec. to 0.01! sec per page request. Well, these are my thoughts about it now, while I don't really know what to think about it. Can somebody put me on the right track here?
 
Here's my two cents:

There is another function called [tt]include_once()[/tt]... look it up at for more details.

As far as I know frequently used files are cached by PHP/Zend (not 100% sure, though).

If includes are not cached, putting all the functions in one BIG include (whatever.inc.php) may save a little time. However, this may not be woth while, since data are read as whole clusters from the harddrive so you may save only very few KBs.

F.ex. my HD has a cluster size of 4KB, so a 1KB (any)file will be read as 1 cluster (4KB) and a 5KB (any)file will be read as 8KB etc.... do you see where I'm going?

Hope this helps §:O)


Jakob
 
IMO the best way of an include statement is to provide the possibility to structure your code in way that makes it maintainable - I would not worry about disk access time. In the grand scheme of HTTP access to resources the 10ms seem to be quite negligible.
Writing the code in a fashion that is resource optimized is a great idea, but disk access time is so machine specific that I would not worry about it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top