Important Optimization Techniques to Improve Performance of Symfony Applications

Symfony, the open source framework allows for the development of scalable and high performance PHP applications. There are a few potential optimization points which when considered during Symfony application development can significantly boost up the baseline performance of the applications. These are as follows.

Symfony Application Development

Service Construction:
The performance of Symfony applications is effected by the event listeners and services. Depending on how expensive it is to instantiate the event listeners and services for various HttpKernel lifecycle, the baseline performance of these applications will be effected.  However, there are certain things one can avoid during services creation in Symfony application development process for better application performance.

  • Avoiding doing work in service constructors which can significantly reduce the performance of applications.
  • Do not inject services in unrequired listeners. This can avoid performance overheads.
  • Creating services with deep dependency layers is time consuming task in Symfony web development process. A better way is to use security component with FOSUserBundle and security wall setups.

Kernel Event Listeners:
The baseline performance of Symfony applications is also effected deeply by the slow event listeners that are executed in every request. So, as a better practice always make sure not to call a database or external services in listeners which can drastically slow down their process. A special case however here could be the usage of security component with the Doctrine or Propel based user object. Here if the user object has lot of properties or data associated with it, then it can significantly slow down the application performance because every time object is called from database for every request.

Internal Sub Requests:
Applications with various views on single page can be decoupled with internal sub requests that allow for calling or rendering the multiple controllers within the same PHP request. However, excess using of internal sub requests can slow down the performance of your Symfony application because every sub request will undergo the HttpKernel event lifecycle and therefore will lead to increase in response times.

Never render sub requests in loops and make it a habit to use Twig {% include %} statement instead of sub controllers. This will significantly reduce the time overheads in Symfony application performance.

Delegate Work to Background:
A better way to improve Symfony baseline performance is to delegate critical work like mails sending, processing the uploaded files and images etc., to the background. When FPM is used for this purpose, the kernel.terminate event is executed after sending response to user. However, depending on kernel.terminate for too much work will not be reliable and therefore, a better way for it would be using an existing message queue.

Framework Overhead by using Number of Libraries & Bundles:
Symfony supports number of libraries and third party bundles like Guzzle, Buzz, Propel, FOSUserBundle, FOSRestBundle etc., which adds to the framework overhead. Symfony application development calls for selecting appropriate libraries or third party bundles for desired performance level. This will move the baseline performance of Symfony applications significantly.

Hence, by following the above optimization techniques one can drastically improve the performance of their Symfony applications.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...