I have been working on the phpShop project at http://www.phpshop.org. One of the tasks that I was recently working on was to go through and streamline the code and look for any performance bottlenecks that might be there.
Well, we found the bottleneck in performance and it seems that there is essentially nothing we can do to make it better. This is the problem:
Each time the parser loads (i.e. index.php3) it has to load all of the class and function files into memory. It does this by reading each file, checking syntax and then of course saving things in memory until they are called; if ever. After several tests we found that even if we have one huge file with all the classes and functions in it, this portion of processing consumes the most resources.
We originally thought we would have to focus on the database and making it faster through the use of indexing, etc. Then we thought that maybe the include's and require's were slowing it down. But no, the time killer is simply loading the class and function libraries into memory; even if your entire PHP application and all its functions and classes are in index.php3.
We even tried using class and function libraries that were not of our own making. There too we see that simply loading them into memory is, well, slow. One thing to note is that we saw a narrow increase in performance when loading functions versus loading classes. But the increase in performance is so small that it is almost a non-issue. The bottom line is that this bottleneck is a PHP related issue. The more code you write and include in your PHP application, the slower it gets, simply by the fact that it needs to read more code on every load.
I am posting these notes in the hope that someone out there has run into this and possibly can recommend a solution. However, after some intense review of the performance of phpShop, the bottom line is that over 75% of the processing time on each page load is consumed by the loading of the classes and functions. That's the bottleneck that we are up against. The only solution we have so far is to make sure our hardware is really fast, especially the hard drive. I am curious to know how other PHP projects have dealt with this issue.
Are we simply writing an application that is too big? What do you think??