I've decided to test the performance of two popular PHP frameworks - Laravel and Symfony. The results surprised me.
The performance test which I've conducted is quite simple. I've created two projects in Symfony and Laravel with only one page, no database queries, no API calls, and no complex calculations, just one simple page. Then I ran HTTP stress tests using a benchmarking tool against both setups and the results are surprising.
Symfony version: 5.4
Laravel version: 10.10
Did you know that Laravel uses a lot of Symfony components under the hood?
Symfony is known for making really good components used across the whole PHP ecosystem in numerous packages. Most of the Symfony components can be used as a standalone package without the need for Symfony itself, which is quite handy.
Let's start with the fun part.
The test environment
Similar to my mod_php vs php-fpm performance tests I've used exactly the same setup:
- Machine: Hetzner VPS with 2 dedicated AMD CPUs, 8GB RAM, 80GB SSD
- Benchmark machine: separate VPS (in the same region)
- Benchmark tool: bombardier (golang)
- OS: Ubuntu 22.04
- PHP version: PHP 8.2.9
- php-fpm web server: nginx/1.18.0 with php-fpm 8.2.9
- php.ini custom config:
// php.ini // default config opcache.memory_consumption=256 opcache.max_accelerated_files=20000 opcache.validate_timestamps=0 realpath_cache_size=4096K realpath_cache_ttl=600
The exact command to run the tests is
bombardier -c 100 -d 1m -l http://IP_HERE/
which translates to
- Concurrent requests: 100
- Duration: 1 minute
Let's see how both frameworks did in the test.
Average requests per second (higher is better)
- Symfony: 775.52
- Laravel: 118.36
Symfony is 6.5 times faster than Laravel.
Average latency (lower is better)
- Symfony: 128.82ms
- Laravel: 840.48ms
Again, Symfony is 6.5 times faster than Laravel.
Max latency (lower is better)
- Symfony: 0.33s
- Laravel: 3.98s
Symfony is 12 times faster than Laravel.
Once again, Symfony performs better with stable performance.
Laravel test results
$ bombardier -c 100 -d 1m -l LARAVEL_PROJECT_IP Bombarding http://LARAVEL_PROJECT_IP:80 for 1m0s using 100 connection(s) [====================================================================================================================================================================================] 1m0s Done! Statistics Avg Stdev Max Reqs/sec 118.36 73.16 440.81 Latency 840.48ms 430.55ms 3.98s Latency Distribution 50% 740.39ms 75% 1.06s 90% 1.39s 95% 1.64s 99% 2.42s HTTP codes: 1xx - 0, 2xx - 7196, 3xx - 0, 4xx - 0, 5xx - 0 others - 0 Throughput: 165.44KB/s
Symfony test results
$ bombardier -c 100 -d 1m -l SYMFONY_PROJECT_IP Bombarding http://SYMFONY_PROJECT_IP:80 for 1m0s using 100 connection(s) [====================================================================================================================================================================================] 1m0s Done! Statistics Avg Stdev Max Reqs/sec 775.52 62.82 1431.45 Latency 128.82ms 7.23ms 333.25ms Latency Distribution 50% 127.85ms 75% 130.33ms 90% 133.42ms 95% 135.37ms 99% 139.94ms HTTP codes: 1xx - 0, 2xx - 46623, 3xx - 0, 4xx - 0, 5xx - 0 others - 0 Throughput: 0.90MB/s
I'm not exactly sure what happened here. The difference seems so big that I start to question my setup and configurations. I've checked the Laravel config, I've enabled route caching and view caching, and debug mode is off...
The clear winner is Symfony by a big margin. I'm shocked by these results. I was expecting a similar performance +-10% diff in favor of one or the other.