Reading the Symfony2 performance docs: http://symfony.com/doc/2.8/performance.html
I'm trying to figure out which solution is better for caching class name paths. I'm using PHP7 so APC is not available, just apcu and opcache. Given that I don't have any issues with complexity of implementing a cache or having to restart the web server, which would be the most performant? Also, if I do go with the APC Autoloader, the app.php code still has to load the composer autoload.php first, create the ApcClassLoader, then unregister the initial autoloader. Would it make sense to clear out the class map so that unused map is not wasting so much memory, i.e. run: composer dump-autoload --no-dev
?
The 'gold standard' for the setup of autoloading in production is as the symfony docs say: composer dump-autoload --optimize --no-dev --classmap-authoritative
.
In Development, such optimisations are probably too much, as every new class you write will need at least a composer dump-autoload
- and flexibility is more useful.
Once the classmap has been written to disc once, and then read back in, it will be available via OpCache anyway, and so it would effectively already been within the PHP process space for maximum speed.
To add some extra speed to the use of the OpCache, one more thing that you can do is stop it from checking for modifications for the cached files - this can be turned off by setting opcache.validate_timestamps = false
. If the files are changed, then you will have to restart the PHP server (php-fpm, or Apache if you are using mod_php), or otherwise invalidate the OpCache caches.