Symfony Article

Symfony Article

Symfony can handle 660 requests/second and work great but you need to do some optimizations for that. Few Symfony sites are handling 1 billion requests per week without any issues. Its all about how you follow framework standards and optimize the site.

Use Symfony forms carefully:
Symfony form is one of the most useful and complex features of Symfony framework. Forms can handle almost everything you are doing like sub-forms, the collection of fields, validation based on condition, reusable fields, auto data rendering and value selection for fields.
In earlier Symfony 2 version there were some performance issue if you do not use proper symfony standards in forms. In a new version of Symfony, they have optimized a lot. But think use symfony form if you really need it. Otherwise, you can use plain form also. Make sure there are no multiple Symfony forms on a single page.

Start using stopwatch component:
Use stopwatch component so you can measure time which code takes how much time to run. you can store stopwatch data in profiler component and then see information in profiler. It will be amazingly useful for speeding up your web pages.
Use kernel.terminate event
Symfony kernel.terminate event is run after response sent to the user. So if you want to send mail then do in kernel.terminate. Think you are loading a page and mail is sending and then user see a response, so here the user has to wait for few seconds. But if you send a mail-in kernel.terminate then the user will see the fast response. So anything that can be done in the background you can run in kernel.terminate.

Use cache:
Use varnish cache, HTTP cache.
Symfony has great documentation for http cache. http://symfony.com/doc/current/http_cache.html By caching you will get faster performance.

Try to avoid subrequest:
Avoid subrequest, means calling another controller action from one action or render Symfony controller action in twig. It will decrease performance. Use twig include statement. If view cannot do some work that you want to do then use twig extension.
Doctrine optimizations
Have limited connections open. See Symfony profiler. You can see how many queries are run on the page. You can also see query loading time. You can group similar statements in profiler and then do some optimizations in your query.

Doctrine optimizations:
Have limited connections open. See Symfony profiler. You can see how many queries are run in page. You can also see query loading time. You can group similar statements in profiler and then do some optimizations in your query.