Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

PHP preloading and Symfony

Blackfire callgraph of the benefit of using PHP preloading

PHP 7.4 added support for preloading. To make a long story short, it gives you extra performance for free. Symfony 4.4 made it easy to benefit from this feature in your projects.

You might wonder how easy it is to benefit from it? It is actually surprisingly easy. When Symfony builds its cache, it automatically creates a file to help PHP preload some PHP files. To enable preloading, you must tell PHP where this file is stored in its php.ini configuration file:

1
2
3
4
5
6
7
8
# as of 4.4.14 or 5.1.6
opcache.preload=/app/src/.preload.php

# on Symfony 5.1+ before 5.1.6
opcache.preload=/app/var/cache/prod/App_KernelProdContainer.preload.php

# for Symfony 4.4 before 4.4.14
opcache.preload=/app/var/cache/prod/srcApp_KernelProdContainer.preload.php

That’s it!

I’ve done it on all the websites I manage for my Open-Source projects. Here is the boost on the twig.symfony.com homepage:

On more complex websites, with database accesses, the percentage is going to be less dramatic, but still interesting.

On SymfonyCloud, the default php.ini template now contains this configuration, so uncomment the right line depending on your Symfony version and enjoy a nice and free performance boost!

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

Comments

Great news!

P.S: The link to http://twig.symfony.com is wrong
Nice and simple. I like it.

How can I get such a profiler into my app?
@Josef It's very easy, just create an account on https://blackfire.io, open the docs and follow this guide https://blackfire.io/docs/book/index
Thank you 😊
Login with SymfonyConnect to post a comment