i am working in 2 different projects using symfony 2.8.12 and having the same problem: performance.
It takes too long to load ( not all the times, but the most part ) and when i look the profiler there is always one "guilty component": it can be the firewall, the controller, the profile listener, the kernel response....being the execution time of several seconds ( sometimes longer than 10 ).
Reading in different threads i tried to set the db as a fix ip ( in case it is a dns lookup problem ), modified some parameters in php.ini but nothing changed. This is hapenning both in my local and in the remote environment where it has even PHP acceleration and OPCache enabled.
I am not doing nothing special on my code, even i get long times in "hello world" pages, it's a little frustrating :)
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.
realpath_cache_size = 4096k
realpath_cache_ttl = 7200
composer dump-autoload --optimize
- this creates dump file with loaded classesconfig_prod.yml
:doctrine: orm: metadata_cache_driver: apc result_cache_driver: apc
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With