Pardon me if this subject has been discussed, but a search of the archive didn't bring up much of anything.

Bear with me while I dish out some details. My question concerns the efficiency of using multiple file includes versus storing segments of data in one include as arrays or functions.

While rebuilding the core of my web site network and, after reading some negative things about file includes, I was forced to rethink how I am structuring things.

Here are some details:
*One domain serving, with around 5 sites as subdomains currently and more soon to come.
*Each script on every site includes a global file that has sessions stuff and network-wide functions.
*Each script includes a header.php file for the specific site's layout.
*Each script includes a footer.php for ditto.
*I am currently on a virtual server, but obviously will need to move on to a dedicated very shortly.


It is my understanding, as disk reads are so slow, that it is not a good idea to include multiple files. I always knew this, but I never really thought about it.

While thinking of how to optimize it, I considered merging header.php and the global file as one. However, I then realized some scripts access the database before including the header as to dynamically change meta tags (say, for Articles). I could use output buffering but, well, I'm not going to.

So I was thinking of making one include file that contained the following:
The former "global" contents (which I'd have to use a batch file to manage this section of the file for all sites at once, no big deal), "header.php" as a function, and the same for "footer.php".


My main question is, will this, with any certainty, be more considerably more efficient than simply including three files? Would it be more efficient to put "header" and "footer" in arrays? Keep in mind I'd have to use eval() on "header" as all of my headers contain some php code. Another method that would involve using eval() would be to store the headers and footers in databases, but I highly doubt this would be more efficient than storing them in arrays or functions.

Another situation, which I am quite certain would benefit from using a function instead of an include, is that of scripts using forms. These forms need to be included on more than one line, such as when the data is empty or invalid and the form needs to be shown again. But forms are relatively small compared to most of my headers.

So there you have it. How does an include compare to a function or a function to an array? Is there a big difference in how the data is stored in memory with a function versus an array? Would one choice be more efficient on a virtual server, while another more efficient on a dedicated (because of memory considerations)? I'm going to just assume the database is not the most efficient choice here.

Thank you to all those who will respond, and even those who simply read this whole message.

-Rob Paxon

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to