Symfony issues

I work in 2 different projects using symfony 2.8.12 and having the same problem: performance.

There is too much time to load (not all the time, but most), and when I look at the profiler, there is always one “guilty component”: it can be a firewall, a controller, a profile listener, a kernel response ... that is a few seconds runtime (sometimes longer than 10).

example case case 2 example

Reading in different threads, I tried to install db as an ip fix (in case it is a dns search problem), changed some parameters in php.ini, but nothing changed. This happens both in my local and remote environment, where it even has PHP and OPCache acceleration.

I don’t do anything special in my code, even I get a lot of time on the “hello world” pages, this is a little frustrating :)

0
source share
2 answers

This is because symfony has thousands of files to read before even starting to print "Hello world". In fact, your hard drives have the greatest impact on Symfony performance. Fortunately, there are a few simple steps to achieve a satisfactory level.

  • php.ini:
    set these two parameters to much higher values ​​than the default value, i.e. realpath_cache_size = 4096k
    realpath_cache_ttl = 7200
  • dump linker autoload:
    composer dump-autoload --optimize - creates a dump file with loaded classes
  • I do not know how you use opcache, but I recommend that you install the apcu module. After that, use the metadata cache in symfony config_prod.yml :
      doctrine:
     orm:
         metadata_cache_driver: apc
         result_cache_driver: apc
    
  • Your website / app.php should look like a few extra lines compared to the usual 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 greatly improves efficiency,
  2. Use PHP with FPM (FastCGI Proces Manager)
  3. Use SQL solution for query caching, i.e. Redis, Elasticsearch
  4. Disable xdebug - make sure that the profiler is not showing that you are using it.

The list is actually long, but the first 4 points plus the 8th of them do the trick in most common cases. Hope this helps.

+7
source

Do you have the xdebug extension in php.ini?

If so, try disabling it, especially in a production environment.

+1
source

Source: https://habr.com/ru/post/944143/


All Articles