Problems with symfony performance Problems with symfony performance symfony symfony

Problems with symfony performance


This is happening because symfony has thousands of files to read before even starting to print "Hello world". In fact your hard drives have greatest impact on efficiency of symfony. Fortunately there is few simple steps to achieve some satisfactory level.

  1. PHP.ini:
    set those two parameters on much higher values than default, i.e.
    realpath_cache_size = 4096k
    realpath_cache_ttl = 7200
  2. dump composer autoload :
    composer dump-autoload --optimize - this creates dump file with loaded classes
  3. I don't know how you use opcache, but I encourage you to install apcu module. After that use metadata cache in symfony config_prod.yml:
    doctrine:orm:    metadata_cache_driver: apc    result_cache_driver: apc
  4. Your web/app.php should look have some additional lines comparing to regular one:

    use Symfony\Component\HttpFoundation\Request;use Symfony\Component\ClassLoader\ApcClassLoader;$loader = require __DIR__.'/../app/autoload.php';include_once __DIR__.'/../app/bootstrap.php.cache';$apcLoader = new ApcClassLoader(md5($_SERVER['HTTP_HOST']), $loader);$loader->unregister();$apcLoader->register(true);require_once __DIR__.'/../app/AppCache.php';$kernel = new AppKernel('prod', false);$kernel->loadClassCache();$kernel = new AppCache($kernel);Request::enableHttpMethodParameterOverride();$request = Request::createFromGlobals();$response = $kernel->handle($request);$response->send();$kernel->terminate($request, $response);

Other but also very important:

  1. Use PHP 7, which has significant efficiency boost,
  2. Use PHP with FPM (FastCGI Proces Manager)
  3. Use No SQL solution to cache queries, i.e. Redis, Elasticsearch
  4. Disable xdebug - make sure that profiler doesn't show you use it.

The list is long in fact, but first 4 points plus the 8th one do the trick in most common cases.I hope it'll help.


Do you have xdebug extension enabled in php.ini ?

If it's the case, try disabling it, specially in production environnement.