Performance

    If your production server still uses the legacy APC PHP extension instead ofOPcache, install the in your application to enablecompatibility with APCu PHP functions and unlock support for advanced Symfonyfeatures, such as the APCu Cache adapter.

    Use the OPcache Byte Code Cache

    OPcache stores the compiled PHP files to avoid having to recompile them forevery request. There are some byte code caches available, but as of PHP5.5, PHP comes with built-in. For older versions, the most widelyused byte code cache is APC.

    The default OPcache configuration is not suited for Symfony applications, soit's recommended to change these settings as follows:

    Don't Check PHP Files Timestamps

    After each deploy, you must empty and regenerate the cache of OPcache. Otherwiseyou won't see the updates made in the application. Given that in PHP, the CLIand the web processes don't share the same OPcache, you cannot clear the webserver OPcache by executing some command in your terminal. These are some of thepossible solutions:

    • Restart the web server;
    • Call the or opcache_reset() functions via theweb server (i.e. by having these in a script that you execute over the web);
    • Use the cachetool utility to control APC and OPcache from the CLI.

    When a relative path is transformed into its real and absolute path, PHPcaches the result to improve performance. Applications that open many PHP files,such as Symfony projects, should use at least these values:

    PHP disables the cache when the config optionis enabled.

    Optimize Composer Autoloader

    The class loader used while developing the application is optimized to findnew and changed classes. In production servers, PHP files should never change,unless a new application version is deployed. That's why you can optimizeComposer's autoloader to scan the entire application once and build a "class map",which is a big array of the locations of all the classes and it's storedin vendor/composer/autoload_classmap.php.

    Execute this command to generate the class map (and make it part of yourdeployment process too):

    • excludes the classes that are only needed in the developmentenvironment (i.e. require-dev dependencies and rules);
    • —classmap-authoritative creates a class map for PSR-0 and PSR-4 compatible classesused in your application and prevents Composer from scanning the file system forclasses that are not found in the class map. (see: ).