phpclassoptimizationhierarchy

How to consolidate / eliminate PHP includes for class files


I have multiple files that I keep including individually. I want to just put them all in one file to decrease file I/O and just have one include.

Update

Ended up using an auto-loader here is the php.net reference. Now I don't have to explicitly include each file and according to the reference the files are lazy loaded.


Solution

  • PHP will parse the file. PHP will probably register the classes, and will in any case parse and syntax check the file. But this might still be faster than loading separate files. More separate file I/O will be slower, though it will require less memory because only the needed files are loaded.

    I wouldn't worry about either, because memory consuption for the classes alone is close to nil. File I/O will probably not be a problem either. You may have APC cache, which keeps compiled versions of the PHP files into memory, and if not, your OS will probably have some caching features which cause often used files to be loaded faster.