Alternative PHP Cache (APC) and __autoload() interoperability
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
Many developers writing object-oriented applications create one PHP source file per-class definition. Using __autoload() helps to overcome one of the biggest PHP annoyances such as having to write a long list of needed includes at the beginning of each script (one for each class).
Although using __autoload is convenient, level of its efficiency with opcode cache is not that obvious. Here go the quotes of two well-known PHP professionals to clarify the situation:
Andi Gutmans wrote:
I don’t see a reason for byte code caches not to work with __autoload() and conditional classes already today. I don’t know of the internals of APC but __autoload() should not really be an issue (it’s just another include() ) and I’m not quite clear why Rasmus thinks that doesn’t work. As far as conditional class declarations are concerned, it’s also not a huge issue. It might not be quite as fast as ones in the main block but you still get the majority of the bytecode cache benefit which is that you don’t need to re-read the file, do lexical analysis and run a parser on it the code…
Rasmus Lerdorf wrote:
To clarify, of course conditionally included files get compiled and cached. The issue is not the included files but the resulting conditionally defined classes and functions needing to be redefined on every request. Whether that is significant or not comes down to the specifics of the situation, but there is no doubt that it is slower. It comes down to a NOP vs. a FETCH_CLASS, for example and the NOP is obviously way faster.
Notes
At present time this PECL extension is not bundled with PHP. New releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/apc. The DLL for this PECL extension may be downloaded from either the PHP Downloads page or from http://pecl4win.php.net/. More details can be found in PHP manual.