Symfony 2 performance optimisations
These points can optimise your application performance:
Upgrade PHP. The performance gain between PHP 5.3 and PHP 5.4 is very high. PHP 5.5 would be even better, but it's not supported by all distributions, like Debian 7.
NGINX is faster than Apache and the configuration is easier.
Using PHP-FPM with NGINX is a good combination. You can also run your PHP with HHVM which is in average 2x faster than PHP-FPM, provided you replace Symfony/Assetic with Grunt. Caution: HHVM requires more precaution and testing before deploying safely. You can follow these two articles (in French): JoliCode and Big Brains Company
PHP APC extension is deprecated. I think that XCache, Memcached or Redis are better, and they're also most supported at the moment. For PHP >= 5.5, APCu can be used as a replacement for APC.
Additionally, you can read a few articles which talk about Symfony2 optimisation and provide Twig benchmarks.
PHP articles:
- Script high-performance in French
- Comparison of PHP 5.3 and PHP 5.6 performance in French
- Check this article to apprehend the PHP optimisation in French
Google's recommendations for optimising PHP applications in English- 10 best pratices to optimise PHP in English
Symfony2 and Twig articles:
- Symfony documentation gives a few tips how to build a performant application in English
- Template optimisation in French
- Twig include optimisation in French
- Use @Cache annotation requests in English
- Symfony2: Good practices in French
- Limit the usage of unnecessary bundles
- Symfony2 Twig performance optimisation in English
- If you don't want to use the Twig Engine, you can disable it in French
- Caching in Symfony from it's Cookbook - really impressive!
Others optimisations:
- Maybe you can use an updated version of Ubuntu.
- Personally, I prefer using Debian which is also popular for servers because it's very stable.
- Using a cache proxy like Varnish can be a finishing touch.
- Varnish requires a developer's implication and maybe a formation. Using NGINX FastCGI Cache to limit FastCGI requests to HHVM, FPM or PHP-NG can resolve speed response.
Did you look this blog post ? http://symfony.com/blog/push-it-to-the-limits-symfony2-for-high-performance-needs
According to your information, i can advise you to try php 5.5 or 5.6 and NGINX with PHP-FPM, it can 40% faster or more.
You can try approach suggested in this article: http://stfalcon.com/en/blog/post/performance-symfony2-doctrine2-orm
The author suggests to:
- Download all necessary connections
- Update multiple entities by request
- Get data as an associative array
- Use reference proxies
- Don't forget to use Symfony profiler toolbar
The code described is availiable on github: https://github.com/lensky84/performance