• 6
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Symfony 2 performance optimisations

We're looking for a PHP framework to work with in future and are currently testing out things with Symfony 2. For this, we've redesigned our API and implemented it as a bundle in Symfony. It turned out that Symfony seems to be very slow - actually far slower than our old (not even well-designed) system.

We tried to optimise the performance by caching the byte code (using APC for this). While we've noticed a huge improvement in performance (before: about 3 seconds to load the API; after: 0.6 seconds in average (still 0.5 seconds slower than our old system without APC)), we're kind of excited - but still not really pleased with the high loading time of such an easy task like getting one result out of an almost empty database.

I don't know, but I could imagine this is due to Symfony autoloading all classes, even when not needed for a specific bundle.

Now, before we deep-six Symfony, we'd like to look out for further optimisations, possibly a way to exclude unneeded components in a specific bundle, as I personally think this would make a big difference.

I'd be thankful for any ideas on how to further improve the performance, experience reports with using Symfony or anything else that could be helpful for us on the lookout for a framework.

Edit:

Some information about the testing environment:

  • Operating system: Ubuntu 12.04.4 LTS (GNU/Linux 3.8.0-38-generic x86_64)
  • Apache version: Apache/2.2.22 (Ubuntu)
  • PHP version: 5.3.10-1ubuntu3.13
  • Considerable PHP extensions: apc

Also, all tests are done on a local copy of our system, so possible network issues can be excluded.

      • 1
    • This is a broad question. Are your running on prod environment? Did you manage to find where is your performance bottleneck? What operating system and php version are you using?
      • 2
    • @Touki I updated my post and added the requested information. We're also running on prod and cached everything possible.
      • 2
    • Just to address one point: Autoload does not load all classes. There is a cache file that loads quite a few common Symfony classes but by no means all of them. Not even close. And I know you said you are running in production mode but you might want to double check.

These points can optimise your application performance:

  1. 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.

  2. NGINX is faster than Apache and the configuration is easier.

  3. 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

  4. 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:

Symfony2 and Twig articles:

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.
  • 14
Reply Report
    • Thanks for updating your post. We took a look into each of your suggestions and were able to significantly decrease the loading time of our API to under 0.1 seconds, which is awesome and suits our requirements! Thank you very much for your help, +accept your answer.
    • Thanks so far for your answer. Unfortunately, the provided articles are all written in French, and even after hardly focusing on it - I just can't understand a word. :( Are there by any chance any English versions?
    • Yes you have completely reason. I have added few articles in english, I think that you have all tracks for optimize your solution.

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

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions