<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dzmitry Kazbiarovich on Medium]]></title>
        <description><![CDATA[Stories by Dzmitry Kazbiarovich on Medium]]></description>
        <link>https://medium.com/@dimdev?source=rss-329915e0af22------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U7nBtVV3jMkZta3HUSn2oQ.png</url>
            <title>Stories by Dzmitry Kazbiarovich on Medium</title>
            <link>https://medium.com/@dimdev?source=rss-329915e0af22------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:14:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dimdev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[9 PHP runtimes: performance benchmark]]></title>
            <link>https://medium.com/@dimdev/9-php-runtimes-performance-benchmark-cbc0527b9df9?source=rss-329915e0af22------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbc0527b9df9</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[php-development]]></category>
            <category><![CDATA[php-developers]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Dzmitry Kazbiarovich]]></dc:creator>
            <pubDate>Sun, 14 Jan 2024 17:09:50 GMT</pubDate>
            <atom:updated>2024-01-17T19:30:58.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oksycn1WmgojBOuj3dL0g.jpeg" /></figure><p>There are some fairly new players in the PHP runtimes team. It’s interesting to understand how good they are in comparison to well-known and widely used.</p><p>The main questions I wanted to get answers are:</p><ul><li>How many requests per second the runtime can process?</li><li>What’s the average response time each runtime can provide?</li></ul><p>To have fair competition, all runtimes are given the same resources. Almost. If the runtime consists of only 1 container(ex. Nginx Unit), it is run with 1CPU and 1GB of RAM. If the runtime consists of 2 containers(ex. Nginx + PHP-FPM), each container is run with 1 CPU and 1GB of RAM.</p><p><strong>The testing environment</strong></p><ul><li>Each runtime is run in 1 or 2 Docker containers.</li><li>Each container has 1 CPU and 1GB of RAM.</li><li>The load testing tool is in the same Docker network</li></ul><p><strong>Testing application.</strong></p><p>Let’s try something more complex than single-file Hello-World. So, we have:</p><ul><li><a href="https://symfony.com/">Symfony 7</a></li><li>1 controller</li><li>1 view</li><li>no database or any other external service</li></ul><p>Symfony provides the runtime component. According to the official doc it “decouples the bootstrapping logic from any global state to make sure the application can run with runtimes like”. It means, that you can develop the application using any runtime you like, but in production run the most performant. So, we can run the application not only with traditional servers, but with libraries like Swoole, AMPHP, and ReactPHP. Looking ahead, the last two were excluded from the competition.</p><p><strong>Load testing tool</strong></p><p><a href="https://k6.io/docs/get-started/running-k6/">K6</a> was used to run load tests. It was run 3 times for each runtime, with 10, 100, and 1000 concurrent connections within 30 seconds.</p><p><strong>Runtimes</strong></p><ul><li><a href="https://httpd.apache.org/">Apache</a>(prefork mode) + mod_php.</li><li><a href="https://httpd.apache.org/">Apache</a>(event mode) + <a href="https://php-fpm.org/">PHP-FPM</a></li><li><a href="https://nginx.org/">Nginx </a>+ <a href="https://php-fpm.org/">PHP-FPM</a></li><li><a href="https://unit.nginx.org/">Nginx Unit</a> application server.</li><li><a href="https://roadrunner.dev/">Roadrunner</a></li><li><a href="https://nginx.org/">Nginx</a> + <a href="https://roadrunner.dev/docs/app-server-nginx-with-rr/current/en">Roadrunner (fcgi mode)</a></li><li><a href="https://frankenphp.dev/">FrankenPHP</a></li><li><a href="https://frankenphp.dev/docs/worker/">FrankenPHP (worker mode</a>)</li><li><a href="https://github.com/swoole/swoole-src">Swoole</a></li></ul><p>All runtimes are based on <a href="https://hub.docker.com/_/php">official docker images</a>. Volumes are not used, the code of the application is copied to the image during the build. PHP 8.3 is everywhere, except Nginx Unit. At the beginning of 2024 <a href="https://unit.nginx.org/installation/#docker-images">the highest PHP version supported by Nginx Unit is 8.2</a>.</p><p><em>Unfortunately, I didn’t find the up-to-date versions of </em><a href="https://github.com/php-runtime/reactphp"><em>ReactPHP</em></a> and <a href="https://github.com/gingteam/amphp-runtime"><em>AMPHP </em></a><em>runtimes compatible with Symfony 7. PHPPM both </em><a href="https://github.com/php-pm/php-pm"><em>GitHub </em></a><em>and </em><a href="https://hub.docker.com/u/phppm"><em>Dockerhub </em></a><em>look abandoned.</em></p><p>The following PHP and Symfony settings are applied:</p><ul><li>php.ini-production (comes with official docker containers) is used</li><li>Opcache enabled</li><li>JIT enabled</li><li>preload is configured according to Symfony best practices</li><li>Composer autoloader is optimized</li><li>Symfony is run in production mode</li><li>Service container is dumped to a single file</li><li>Symfony cache is warmed up during container build</li></ul><p>The application code, as well as container configs, can be found on GitHub <a href="https://github.com/DimDev/php-runtimes-benchmark">https://github.com/DimDev/php-runtimes-benchmark</a>.</p><p><strong>Results</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UrEYM2Fxl4BAWnvwCmGmzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRijbf53FeQrag4HFZbNbA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JTJ1RHmVZfbtNatP7gKNBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BDDpOUwjTMDIaDPBto22hw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w83C7MxEpFPsnxuSbTGtHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0XRHPbEWKE5GHZRC9bWNA.png" /></figure><ol><li>001_Apache+mod_php and 002_Apache + PHP-FPM showed almost the same results.</li><li>003_Nginx+PHP-FPM is very close to 001_Apache+mod_php and 002_Apache + PHP-FPM when the workload is low (concurrency 10 and 100 ).</li><li>003_Nginx+PHP-FPM was able to serve ~<strong>2 times more</strong> requests than Apache-based stacks when the concurrency is 1000</li><li>004_Nginx Unit. First of all — WOW!!! It is<strong> ~3 times faster</strong> than the traditional and most popular 003_Nginx+PHP-FPM.</li><li>I don’t see a big difference between 005_Roadrunner and 006_Nginx+Roadrunner.</li><li>Nevertheless, Roadrunner-based stacks are more than <strong>~2 times faster</strong> than 003_Nginx+PHP-FPM.</li><li>007_FrankenPHP(non-worker mode) is pretty close to 003_Nginx+PHP-FPM from performance point of view</li><li>008_FrankenPHP(worker mode). Double WOW!!! I didn’t believe from the first attempt and ran load tests 3 or 4 times. So, when sending 1000 concurrent requests FrankenPHP(worker mode) is <strong>&gt;10 times faster</strong> than Nginx+PHP-FPM. Also, faced an issue. <a href="https://github.com/DimDev/php-runtimes-benchmark/blob/main/001_symfony7_wo_db/runtimes/008_frankenphp_workermode/frankenphp/frankenphp.Dockerfile#L22">Couldn’t start the container</a> with php-ini.production.</li><li>009_swoole — also double WOW!. Almost the same speed as 008_FrankenPHP(wm). Extremely fast. But, keep in mind that your code should be adjusted to be run with Swoole. For Symfony we have a <a href="https://github.com/php-runtime/swoole">bundle</a>, which extends <a href="https://symfony.com/doc/current/components/runtime.html">symfony/runtime</a> component.</li></ol><p><strong>Personal opinion.</strong></p><ol><li>FrankenPHP — amazing job, the first candidate to become standard de facto in PHP world.</li><li>Swoole — I want it to be out of the box (but disabled) PHP extension.</li><li>Nginx Unit — my personal choice. Despite it doesn’t support HTTP2 and many other features traditional Nginx provides, it is super easy to configure, light, and fast.</li></ol><p><strong>What’s next?</strong></p><p>It is worth trying the same tests with an application connected to the database.</p><p>Try ReactPHP, AMPHP, and PHPPM-based runtimes. But before that, the appropriate packages need to be updated to work with Symfony 7.</p><p>Run containers with more resources, let’s say 2–4 CPU and 4–8GB of RAM. It would be interesting to see how well the runtimes can scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbc0527b9df9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>