Symfony performance documentation is out of date. We updated it with another committer, but the Pull request is still pending approval. Now I just copy / paste a new document. Here you can find the GitHub Pull request.
Use OPcache Byte Cache
OPcache stores compiled PHP files so as not to recompile them for each request. Some byte cache codes are available, but with PHP 5.5, PHP comes with built-in OPcache. For older versions, the most widely used cache is APC.
Tuning OPcache for Maximum Performance
The default OPcache configuration is not suitable for a Symfony application, so we recommend that you change these settings as follows:
; php.ini ; maximum memory that OPcache can use to store compiled PHP files opcache.memory_consumption=256M ; maximum number of files that can be stored in the cache opcache.max_accelerated_files=20000
Do not check PHP timestamps
On production servers, PHP files should never be changed unless a new version of the application is deployed. However, by default, OPcache checks to see if the cached files have changed their contents since they were cached. This check introduces some overhead that can be avoided as follows:
Note
OPcache is different for web server and command console. You cannot clear the OPCache web server by running some command in your terminal. You either need to restart the web server, or call the opcache_reset () function via the web server (i.e., have this in a script that you execute over the Internet).
Configure PHP Real Path Cache
When a relative path is converted to its real and absolute path, PHP caches the result to improve performance. The default configuration of this cache is not suitable for applications that open many PHP files, such as Symfony. It is recommended that you change these settings as follows:
Configure PHP Real Path Cache
PHP uses an internal cache to save the result of mapping file paths to their real and absolute file system paths. This improves the performance of applications such as Symfony, which open many PHP files, especially on Windows systems.
By default, PHP sets the realpath_cache_size value of 16K, which is too small for Symfony. Consider updating this value to at least 4096K. In addition, cached paths are only saved for 120 seconds. Also consider updating this value with the realpath_cache_ttl parameter:
Optimize composer autoloader
The loader class used in developing the application is optimized for finding new and changed classes. On production servers, PHP files should never be changed unless a new version of the application is deployed. Therefore, you can use Composer autoloader optimization to scan the entire application once and create a βclass mapβ, which is a large array of locations of all classes and is stored in the vendor / composer / autoload_classmap.php file.
Run this command to generate the class map during installation (and thus make it part of the deployment process too):
$ composer install
--no-dev Excludes classes that are needed only in the development environment (for example, tests).
--optimize-autoloader each PSR-0 and PSR-4 compatible class used in your application.
--classmap-authoritative Prevents the collector from scanning the file system for classes that are not found in the class map.
--apcu-autoloader To use this option, you need to install the APCu PHP extension. It will cache classmap in APCu. It will not generate classmap, though, so you should always use it with --optimize-autoloader
Tip
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 features and unlock support for advanced Symfony features such as the APCu Cache adapter.
Note
When using the APCu autoloader, if you add new classes, they will be found automatically, and everything will work as before (that is, there is no reason to "clear" the cache). However, if you change the location of a specific namespace or prefix, you need to reset the APCu cache. Otherwise, the autoloader will still look at the old location for all classes within this namespace.