Choosing a PHP MVC Framework: Yii Vs. Kohana Vs. Home made MVC

Choosing a framework is never an easy task, there are many aspects to consider, the three most important ones are, from my point of view:

  • Available features and community extensions.
  • A good documentation with examples.
  • A low footprint.

The balance between these three values and the impact of each one on your project will determine the good candidate. Since having a wide range of included features and an active community who provides with extensions, we are sure that the wheel won’t be reinvented. Thus, we can become productive much faster.

Secondly, documentation and examples also help to understand the technology and reduces the learning curve, so that, once again, we can do more complex thing much earlier.

On the other hand, against the benefits of a well-known MVC framework, which includes the points above but also security, code structure, and strong development guidelines, we have to consider how the footprint will affect the overall performance.

But is performance a critical point? In a time where servers can be escalated and are costless, should we worry about optimal performance and fast scripts? Well, it depends on your project. I dare say that the vast majority of web sites (according to Pareto principle) can be developed with one framework or another. However, there might be specific cases where optimal performance and low execution time are the key to success.

For instance, with social networking websites. Users do not want to wait for the content to be loaded, search engines are more and more favoring domains with a short load time and, finally, when the service may escalate, the cost related to hosting may save you a significant amount of money by the end of the year.

While there are many ways to make your site load faster, whether you use a framework or not (code cache, html cache, right header cache policies, using a CDN for static files…), it seems logical that the best results on this field are achieved by using low footprint frameworks, or even home brew lightweight platforms, completely adapted to your needs and means.

On the other side, there is the matter of investment, which tends to be more critical when developing a home made platform than when adapting some solution in the market. Once again, it’s up to you to judge what fits better your situation, needs, and possibilities.

A real case

For a project I am working to, I have considered a few solutions to improve the code and be ready for high scalability by increasing coding productivity as well. The first I did is to research a bit about PHP MVC frameworks, their features and drawbacks:

Then I looked for performance benchmarks made by other users. Soon I realized that every project’s official site tends to present their product as clearly the best. Therefore, I have mostly considered third party studies like:

After reading a while, I decided that a good candidate would be Kohana or Yii, because both are light enough, while well documented and rich in features, that is, the best balanced from the output of the research done. The next step I did then was to test them against a raw PHP script on a local server.

The benchmark

To set up the benchmark, I have installed a MAMP environment on a MacBook computer. The results and specifications of the machine are not relevant on themselves, so I will focus on the relative performance between applications. The software used to run the tests is JMeter, a free tool from the Apache project, written in Java and therefore, cross-platform.

The test consisted on a basic script that connected to a database to get 100 results from a table and showed them on a HTML page. I run the battery with and without APC, and the following table shows the results:

Without APC With APC
users rps % users rps %
PHP 500 269 100% 1200 400 100%
Kohana 120 84 3.2% 1000 312 78.0%
Yii 100 22 12.2% 900 289 72.3%
PHPro MVC 400 265 98.5%
Limonade 400 113 42.0%

 

Please note: the first three technologies have been tested with and without APC. This has thrown light over the fact that, despite using APC raises the selected MVC’s performance to an acceptable level, there is also a considerable lose regarding raw PHP.

The last two ones have been run on a second series, after I decided that, despite I am planning  to use APC, it was better to compare the frameworks on their basic installation. Despite using APC is a good idea, it has to be applied to every view generation on a widely manner, so it is better not to rely all the application’s performance on the right use of this tool, but on a certain basis. These two cases (PHPro MVC and Limonade) have been chosen for their low footprint, despite their lack of extensions migh increase the time investment.

Conclusion

As I said before, choosing a framework for your web application is not a trivial task. Normally, any of the most well-known applications would be more than useful. Frameworks like CakePHP, Zend, Yii, Kohana and Code Igniter are well documented, maintained by a big community, rich on features and – some more than others – are considerably fast. Only in some very precise and critical situations we would like to choose some home brew PHP code, and in that case whether Limonade, whether our own PHP MVC framework (and PHPro MVC is a good base architecture to start with) would be the solution we are looking for.

It’s up to you, what are your experiences with high load websites and PHP Frameworks? Which one do you prefer? Comments are welcome 🙂

23/03/2011 Update

Please take a look to MVC Light if you are interested on lightweight home-brew frameworks (it is an evolution of PHPro MVC)

5 thoughts on “Choosing a PHP MVC Framework: Yii Vs. Kohana Vs. Home made MVC

  1. These findings are quite similar to my findings. As pointed out it’s important to consider what you’re using the framework for and whether you’re intending to do everything inhouse or outsource. Overall I have found that of course your own framework is the best, BUT it takes considerable investment of time and a fair bit of skill, so unless you really really need to roll your own it’s best to stick with something like Yii, Kohana or CodeIgniter. These are well established, well documented feature rich frameworks. There is actually little point going with something like Limonade as the features and community isn’t there, and yet it’s not a custom framework. So either use a well established framework OR roll your own (perhaps using PHPPro MVC as the base), but no point going with a less popular and mature framework as then you don’t get the best of either world.

  2. I noticed that you had Yii performance significantly lower than Kohana performance, which isn’t right if you got the config right. You need to make sure you enable DB Schema caching as that makes a massive difference in terms of performance when you’re using the database. I had the same problem when I was doing my benchmarking and found that once DB schema caching was turned on in Yii it worked much faster.

  3. I wouldn’t say that the difference between both applications is significant, with APC (and so I assume with other cache techniques), Koana ‘wins’ by only about 8% over Yii. While there might be many factors affecting the result (the tests where performed on a server running on a normal current desktop computer), all the frameworks should be using the same caching schema to provide reliable results. In my case, I chose to use them as they are configured by default, then use APC as a ‘neutral’ caching system. Their out-of-the-box behavior seemed a fairer comparison to me, I’ve left tweaking the config files for further benchmarks.

    To sum up, I see both frameworks quite similarly in terms of performance, but I think that the results shown here make sense. I do believe that Kohana is a bit lighter than Yii in terms of size of the framework and amount of files being loaded on a default bootstrap. That might explain the difference in performance observed with APC, since the footprint left corresponds to the time the framework takes to load itself and output the result to the browser.

    I can’t but agree with your conclusions, though: the final decision should be made having in mind every single case, being the available documentation and the ease to develop as important as performance, IMHO.

    Thanks for your comment!

  4. seems to be a great framework to me……… wins the comparison.. I’m not a techie personally, so I had to search around to hire a kohana developer and found http://www.kohana.me Can anyone recommend them or any other good kohana developer or a development team, say 3-4 developers?

Leave a Reply

Your email address will not be published. Required fields are marked *