Hi,
What kinds of things should I avoid if I want to support PHP OpCode Caches? Are static calls evil? What about __autoload?
Hi,
What kinds of things should I avoid if I want to support PHP OpCode Caches? Are static calls evil? What about __autoload?
For every PHP-based web-application I've worked on for the past 3 years and a half, I've always used APC as an opcode cache, on all the servers I'm using...
... And I've never had to take of anything "special" while developping : in every case, using APC or not has been transparent, the only difference being about performances.
I've never had any problem with static calls, nor autoloading, for instance -- nor with anything else (And I've worked with a couple of different Frameworks and OSS Applications)
Still, one good habit : if you plan to use APC on your production server, also use it on your development machines, just in case -- but enable the apc.stat
option on those, so your life is not complicated by the opcode caching mecanism.
An opcode cache is made to cache the compiled version of the script. The Zend Engine under the hood always compiles PHP scripts to faster opcodes before running the script, and it is these opcodes the cache will save. You script will therefore behave in exactly the same way as it should without the cache, only be faster to begin running.
The cache engine usually look in the timestamp (modification time, or mtime) of the PHP file. APC can be configured to look up the modification time on every request (the default), but it could also be configured to NOT check for modification time and in that case you have to manually clear the cache to take up changes. See this setting to the APC cache: