Choosing PHP Framework
Why Yii Framework is better than Kohana PHP
I started playing around with both Yii and Kohana in the two PHP IDEs that I use, Eclipse PDT + Aptana and NetBeans PHP. Yii played very nice with both, because it seems the developers also use these IDEs and hence thought about something that’s very important to serious PHP developers IntelliSense / Code Completion. Yii handles code completion perfectly and I can easily press F3 in Eclipse PDT or right-click Navigation->Go to Declaration in Net Beans PHP to go into the source object and see what’s going on. In Kohana however, this is not possible and that’s a MAJOR NEGATIVE, because it makes learning the framework so much more difficult as you don’t have code completion. This stems from how Kohana does auto-loading (and it’s not alone, I’ve seem the same problem in the custom framework that OpenCart uses). Basically it uses a registry and a loader class but there isn’t a one-to-one relationship between the class name and what it’s called when used. For example, the html helper in Kohana is declared as html_Core, while when used it’s usually html::somestaticmethod. Because html_Core is not html the IDE can’t make the connection! Also, why does Kohana use lowercase for helper classes? The standard is generally to use ProperCase for class names and camelCase for variables (and usually for functions). This issue with IDE support is in itself for me a reason to choose Yii over Kohana!
Other things that make Yii the better choice for me are the fact that when I use it, it just feels natural! It’s like the lighter version of .NET and Zend and with CodeGeneration capabilities so I don’t have to write everything by hand.
Performance wise both are about the same, but I’ll write a separate post on performance as I benchmarked both.
Regardless, all other thigns aside, the lack of proper IDE Code Completion support in Kohana is a deal-breaker for me and is a big enough reason to choose Yii Framework over Kohana! Unless you’re already super familiar with Kohana or are stuck in the dark ages (or think you’re tool l33t for an IDE), using Yii will greatly improve the speed with which you’ll be able to get up and running with a new framework. Combine that with code generation that Yii provides and you’re onto a winner unless of course it doesn’t meet some other needs that you have and you prefer to roll your own (which requires a significant investment of time and skill).
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.
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:
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.
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