Hi, Tuesday, March 16, 2004, 3:23:35 PM, you wrote: RP> Pardon me if this subject has been discussed, but a search of the RP> archive didn't bring up much of anything.
RP> Bear with me while I dish out some details. My question concerns the RP> efficiency of using multiple file includes versus storing segments of RP> data in one include as arrays or functions. RP> While rebuilding the core of my web site network and, after reading some RP> negative things about file includes, I was forced to rethink how I am RP> structuring things. RP> Here are some details: RP> *One domain serving, with around 5 sites as subdomains currently and RP> more soon to come. RP> *Each script on every site includes a global file that has sessions RP> stuff and network-wide functions. RP> *Each script includes a header.php file for the specific site's layout. RP> *Each script includes a footer.php for ditto. RP> *I am currently on a virtual server, but obviously will need to move on RP> to a dedicated very shortly. RP> It is my understanding, as disk reads are so slow, that it is not a good RP> idea to include multiple files. I always knew this, but I never really RP> thought about it. RP> While thinking of how to optimize it, I considered merging header.php RP> and the global file as one. However, I then realized some scripts RP> access the database before including the header as to dynamically change RP> meta tags (say, for Articles). I could use output buffering but, well, RP> I'm not going to. RP> So I was thinking of making one include file that contained the following: RP> The former "global" contents (which I'd have to use a batch file to RP> manage this section of the file for all sites at once, no big deal), RP> "header.php" as a function, and the same for "footer.php". RP> My main question is, will this, with any certainty, be more considerably RP> more efficient than simply including three files? Would it be more RP> efficient to put "header" and "footer" in arrays? Keep in mind I'd have RP> to use eval() on "header" as all of my headers contain some php code. RP> Another method that would involve using eval() would be to store the RP> headers and footers in databases, but I highly doubt this would be more RP> efficient than storing them in arrays or functions. RP> Another situation, which I am quite certain would benefit from using a RP> function instead of an include, is that of scripts using forms. These RP> forms need to be included on more than one line, such as when the data RP> is empty or invalid and the form needs to be shown again. But forms are RP> relatively small compared to most of my headers. RP> So there you have it. How does an include compare to a function or a RP> function to an array? Is there a big difference in how the data is RP> stored in memory with a function versus an array? Would one choice be RP> more efficient on a virtual server, while another more efficient on a RP> dedicated (because of memory considerations)? I'm going to just assume RP> the database is not the most efficient choice here. RP> Thank you to all those who will respond, and even those who simply read RP> this whole message. RP> -Rob Paxon On a busy site (where the milliseconds start to matter) the chances are that the operating system has your include files cached so the load time is probably not a factor. If you install some of the php token caching systems (zend and others) the speed is even better. As to using header and footer includes I found that system really frustrating trying to follow the html. What I have switched to is templates where the site layout is a template and each php page generates the content and passes it one include file that does the final mix. this way my html developer has control over the html and can edit it as one file most of the time. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php