Page 1 of 1

Many include files or just one?

Posted: Sat May 22, 2004 9:17 am
by Xephon
Was wondering if it was better to break the include file into many include files. Say I make a LARGE site (forums, portal, gallery, etc) and they are al integrated. Would it be better to make one large include file, or several small ones like phpBB and postnuke do?

If I just do one large one, then the server will most likely cache it, otherwise it would have to constantly access the hd to get each include file, which would seemt o be slower. So by my logic one large file would seem to be faster since it owuld be cached. But I would like to know for sure before i start coding the site.

Thx in advance.

Posted: Sat May 22, 2004 9:37 am
by jason
Many include files. Optimize for yourself, and just include intelligently. Nothing is worse than having to edit a 6000 line file. It's bulky, and makes updating more dangerous.

You will have other problems before you ever have to worry about whether to include on file or many.

Posted: Sat May 22, 2004 10:39 am
by launchcode
One large include file WILL be faster because there is far less seeking on the HD - however it is a nightmare to maintain as Jason has said.

For one of my sites I have all the files split up locally and then have a script which sticks them all together into one giant file (so 1 include) which is then uploaded for each new version of the site.

It cut file access times from around 800ms down to just over 200ms making this one change alone.

But it really does depend how many files you have and how often you'll be updating the site.

Posted: Sat May 22, 2004 11:14 am
by kettle_drum
Its also MUCH easier to re-use your code if you have classes and functions that relate to each other in seperate files as you can just copy the file rather than cut and paste bits from a larger file.

Plus, unless you are doing something that requires incredible fast load times, an extra few hundred milliseconds isnt noticiable. Remember dial-up users can only download at like 4kb/s and consider that the average page is probably about 30kb, it takes a lot more time to download the page as to create it.

Posted: Sat May 22, 2004 11:39 am
by launchcode
Classes and functions can relate to each other regardless of it they are in one single file, or split up all over the place and then included together.

All PHP does when you access your script is to include all of the PHP files that you include/require into one large memory resident area before parsing all your code. How it achieves this end result (one include vs. 50) is irrelevant to how your code and talk to each other.

As for a few hundred ms not being noticeable - maybe on a low traffic site, yes I agree totally. But on anything else it can have a big impact - the site in question I use this technique on receives well in excess of a million hits a day (to a single server) - and the longer PHP takes to process your script, the longer Apache has to wait before it can even begin transfering it to the client - regardless of their connection speed.