Symfony
Symfony vs Laravel Performance Benchmark
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.
You can check both projects on my GitHub - Symfony / Laravel.
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.
For example, the laravel/framework packages uses 11 Symfony components (at the time of writing this post), some of which are symfony/routing
, symfony/mailer
, symfony/http-foundation
etc.
Let's start with the fun part.
How to get parameter in Symfony controller
To get parameters in Symfony controller, you can bind a parameter to a variable and inject it into a controller or service.
How to list directory files in Symfony
To list files in a directory with Symfony, you can use the Finder Component - $finder->files()->in(__DIR__);
Let's look at the example below to understand better how the Finder component works.
How to fix Only attribute mapping is supported by make:entity error in Symfony
To fix the Only attribute mapping is supported by make:entity error
error in Symfony, you need to change your Doctrine Entity type in your config/packages/doctrine.yaml
from annotation
to attribute
.
How to use Symfony Query Builder where
In Symfony, the Doctrine Query Builder provides a convenient and object-oriented way to construct complex SQL queries. The where()
method is used within the Query Builder to add conditions to your queries. Here's how you can use it:
How to use Symfony Query Builder delete
The Doctrine Query Builder in Symfony can be used not only to select entities but also to delete them by using ->delete()
.
How to use Symfony Query Builder count
The Doctrine Query Builder in Symfony can be used to count rows by using ->select('count(e.id) as c')
How to use Symfony Query Builder update
The Doctrine Query Builder in Symfony can be used not only for fetching entities but also to update them by using ->update()
.
How to use Symfony redirectToRoute with parameters
To use redirectToRoute
with parameters, pass the route name as the first argument and an array with parameters as the second argument of the method.
Symfony Stopwatch Example
Symfony Stopwatch is a component that allows you to profile and measure the duration of specific parts of your code. It's particularly useful for identifying bottlenecks and optimizing performance. Here's how you can use Symfony Stopwatch: