Search code examples
phpsymfonyapcopcache

Symfony2: Cache a "Class Loader" with OpCache


PHP features a new code caching module called OPCache. Symfony2 recommended to use ApcClassLoader (based on APC) or XcacheClassLoader (based on XCache) to cache the mapping from a class to its containing file. My server (Apache 2.4 with PHP 5.6) use OpCache.

  1. Is there an alternative "cache mapping" for OpCache? I have not found.
  2. I can use APC and OpCache together (I could use ApcClassLoader)? I think not.

Solution

  • The usage of APC makes sense up to PHP version 5.4. But even with 5.4 it is not fully compatible. From PHP 5.5 on, it's better to use APCu.

    As of PHP 5.5 the Zend Opcache is a part of the core PHP distribution. You may combine it with APCu.

    Calls to the old APC functions will be emulated: apc_*()-> apcu_*(). "APC emulation" will show up in phpinfo(), when the APCu ext is loaded.

    enter image description here

    So given PHP 5.6 with OpCache and APCu the SF2 ApcClassLoader should work.

    The answer for question 1: The OpCache is not a full blown cache, like APC, it's a simple opcode cache with some optimization steps. And it's not a userland cache - "just" an internal cache, speeding the processing of PHP up.