Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Include overhead
September 10, 2005, 9:11 am
rate this thread
I'm working on a new web application (php5.1 + postgresql) and i wanted
to have seperated files for each class and use __autoload and i have
everything split to classes now. This makes my pages need to include a
lot of files each request. Do this a huge overhead? I mean shall i go
for gigantic function definition scripts and include all of them at
BTW, my classes are not too big, 4-5 methods and properties each, i
thought having one function definition file might avoid including
overhead but then php will need to interperate all that functions that
i will not use.
What shall i do?
Re: Include overhead
You'd have to test and benchmark both approaches on your system, as it seems
to me there are far too many unknown factors to be able to say one approach has
a clear advantage over the other.
Could this be premature optimisation? I'd be surprised if the absolute
difference between either approach was significant compared with the runtime of
the scripts, particularly since you're communicating with a database.
Might it be best to keep it simple at this stage, i.e. not use autoload but
bear the approach in mind for the future whilst you develop the more important
parts of the code, and then try it out if the size of the included files
appears to be causing a delay?
You might want to look at something like APC which further reduces the cost of
includes by caching the compiled code.
Andy Hassall :: email@example.com :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Re: Include overhead
Measure it for yourself.
I suspect you would need to have a lot of classes to get a benefit from only
a single include file - but then in the real world you're going to have to
load a lot of stuff that you simply don't need - which may offset the
savings you made by consolidating the classes (particularly of you are
using a PHP accelerator).