View Full Version : Your thoughts on include()

01-26-2004, 12:38 AM
I'm wondering if it's efficient processing wise to have large includes files attached to pages. For example, I have this php include file that it all it has are custom string functions. Now, some pages in my apps use most of these functions, while others use only a few, and some use just one. For the pages that use only a few of these functions of this include file, is it worth including that include file? Is it better to just copy that function needed from the include file and put it in the page and don't include the file?

Wondering what you guys think is best. By the way, these string functions are related, so I don't want to split them apart. There's still quite a few of them, and I'm worried about processing time.


01-26-2004, 12:56 AM
do you have a processing timer on your page? It's normally a good idea to keep a track of this in case it starts getting too big and you need to trim it down a tad.

01-26-2004, 05:01 AM
depends who you ask .. ;)

ask a JAVA head and they will tell you to include everything (ok they would be JAVA clases but you know what I mean) as its preferable to have all your code in one place for readability and fefactoring , e.g .you only ever change the scripts in your 1 include/class file instead of finding all the scripts where you used function 'x' and updating those (eg you may have found a better way to implement function 'x')

Of course JAVA is compiled (nearly anyway) and after it's run once, there is no need to keep reinterpreting any included class definitions and the overhead is minimal.

PHP is interpreted, so unless you are employing a low-level cache (Zend Cache etc) your includes get parsed each and every page request, which on a busy page can make a difference.

There are $x ways to get around this from the simple 'dont worry about it', which is actually fine in many cases, to utilising a cache , to simply being happy to do a bit of refactoring now and again, to weird and wonderful code generators which are useful only if you develop within a custom framework.

Often the biggest resource saver can be to look at your output and see what can be pre-`compiled`(to HTML) , eg , you have a database full of data that eventually gets parsed to a HTML table , all the functionality required to do that can be quite an overhead if loaded at runtime , often the chances are that the data only changes in that table once for every 1000 page views .. in that case you could build your HTML table and include it as a static file , whenever the database data changes you rebuild the include , etc.

how big are your includes ? if they total say 100kb+ then I would start thinking about my options , else not worry too much about it.