There are many assumptions around performance of different PHP frameworks. I frequently hear strong opinions about superiority X over Y in this context. There are companies writing new PHP frameworks from scratch because available solutions are too slow for them. What does it really mean? Does the framework performance matters? Before answering this questions lets check how slow is your framework!
Performing a representative benchmark across different framework is not an easy task. There are multiple ways to use each of them. Every use case will give different reading. Lets take routing as an example. Zend1 by default doesn’t need a routing file. It’s happy to use “/controller/action” pattern. On the other hand Symfony2 comes with a routing configuration. The file has to be read and parsed. That obviously takes some additional CPU cycles but does it mean Symfony2 routing is slower then Zend1? The answer is (obviously) no.
I benchmarked “quick start” projects. That gives some idea on what is the base line for every framework and makes it possible to reproduce my tests (and argue against them).
Code was hosted on Amazon EC2 medium instance. I installed PHP-APC to avoid disc access and code parsing. I also made sure there is no I/O on Apache2 or application level. I set logs and cache paths to “/dev/shm/”. I tweaked projects to make them return roughly the same amount of data (10KB). All virtual hosts had the same mod_rewrite rules. AllowOveride was set to None.
- Cake PHP
- Code Igniter
- Fuel PHP
- Hazaar MVC
- Slim Framework
- Symfony 2
- Zend Framework 1
- Zend Framework 2
Requests per second from Apache Benchamrk with c=20 and n=500.
Code Igniter 187.78
Fuel PHP 116.34
Hazaar MVC 103.53
Zend 1 103.02
Cake PHP 54.97
Zend 2 36.1
I’m not surprised, Slim is the fastest because it’s a micro framework. The Quick Start project didn’t use any templates or layout which obviously contributed to the reading.
Zend1 is twice faster than Symfony2 and Zend2 but in my experience the number will quickly go down in a real live setup.
Frameworks should speed up development, performance is a secondary concern. Zend 2 and Symfony2 could do better but it’s not bad. There are ways to improve those numbers on production servers. Don’t reinvent the wheel, learn and use frameworks. There are various options which balance between performance and features.