Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages showcasing Symfony with Docker, APIs, queues & async tasks, Webpack, SPAs, etc.


You are browsing the documentation for Symfony 4.1 which is not maintained anymore.

Consider upgrading your projects to Symfony 5.2.


4.1 version


Symfony is fast, right out of the box. However, you can make it faster if you optimize your servers and your applications as explained in the following performance checklists.

Symfony Application Checklist

  1. Install APCu Polyfill if your server uses APC

Production Server Checklist

  1. Use the OPcache byte code cache
  2. Configure OPcache for maximum performance
  3. Don’t check PHP files timestamps
  4. Configure the PHP realpath Cache
  5. Optimize Composer Autoloader

Install APCu Polyfill if your Server Uses APC

If your production server still uses the legacy APC PHP extension instead of OPcache, install the APCu Polyfill component in your application to enable compatibility with APCu PHP functions and unlock support for advanced Symfony features, such as the APCu Cache adapter.

Use the OPcache Byte Code Cache

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

Configure OPcache for Maximum Performance

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

; php.ini
; maximum memory that OPcache can use to store compiled PHP files

; maximum number of files that can be stored in the cache

Don’t Check PHP Files Timestamps

In production servers, PHP files should never change, unless a new application version is deployed. However, by default OPcache checks if cached files have changed their contents since they were cached. This check introduces some overhead that can be avoided as follows:

; php.ini

After each deploy, you must empty and regenerate the cache of OPcache. Otherwise you won’t see the updates made in the application. Given than in PHP, the CLI and the web processes don’t share the same OPcache, you cannot clear the web server OPcache by executing some command in your terminal. These are some of the possible solutions:

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

Configure the PHP realpath Cache

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

; php.ini
; maximum memory allocated to store the results

; save the results for 10 minutes (600 seconds)


PHP disables the realpath cache when the open_basedir config option is enabled.

Optimize Composer Autoloader

The class loader used while developing the application is optimized to find new and changed classes. In production servers, PHP files should never change, unless a new application version is deployed. That’s why you can optimize Composer’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 stored in vendor/composer/autoload_classmap.php.

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

$ composer dump-autoload --optimize --no-dev --classmap-authoritative
  • --optimize dumps every PSR-0 and PSR-4 compatible class used in your application;
  • --no-dev excludes the classes that are only needed in the development environment (e.g. tests);
  • --classmap-authoritative prevents Composer from scanning the file system for classes that are not found in the class map.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.