We are about to start a project from scratch at my new job and have been evaluating PHP frameworks. We’ve shortlisted CakePHP, CodeIgniter, Symfony and Zend.
I have put them through their paces by building the same application with all four of them (a simple wiki application) and hopefully, we’ll settle on one soon enough.
Full Disclosure: I have tried to be as unbiased as I possibly can but I’m already a CodeIgniter fan. That said, the company I work for is a Zend Partner (we already use the Zend Platform and Zend Studio) and I can’t help factoring that in.
Although the initial plan was to review four PHP frameworks, this post has become a direct CodeIgniter to Zend Framework comparison. I have had to exclude Symfony and CakePHP from the list after spending a few hours going through all four frameworks for the following reasons:
- Learning curve:
Both symphony and CakePHP have a very steep learning curve. CakePHP has strict rules about database table names, where files should be placed, method names and class names. Symfony stores its configuration in .yml format (requires learning although it’s not really that hard) and a lot of the interaction with the application is through a console. Creating database tables, data models and various other files are done using the command line. - Strict ORM:
CakePHP and Symphony have full-blown object-relational mappers (ORM) to provide access to the database and these cannot be disabled without a lot of effort. These ORM have strict rules and conventions which must be adhered to for the application to work.
In contrast the Zend Framework and CodeIgniter are flexible about using models and how they are used. Using a model is optional and while they each have data mappers, applications can work without them. The application will be extremely database intensive and we would rather not be limited in our choices. - Flexibility:
The Zend Framework and CodeIgniter are more flexible than the other two frameworks.
The Duel
CodeIgniter | Zend Framework | |
Set Up | CodeIgniter is very easy to set up. Copy all the framework files to the web server and it’s good to go. It also has a small folder size – about 2.1 Mb and I could display the default home page less than five minutes after I started the set-up. | The Zend Framework requires a bit of effort to setup the project. It requires the creation of a bootstrap file with all the initialisation stuff it. The framework is relatively large – about 12.4Mb and the set-up process took about 19 minutes. |
Documentation | The documentation is very well-structured and organized although it is a bit less detailed than the Zend framework documentation. CodeIgniter also has forums and a wiki which feature a lot of user-submitted code. |
The Zend Framework has very detailed documentation with a lot of examples. It is less organised than the CodeIgniter docs in my view although this could be down to the afore-mentioned detail and the large number of components available in the framework.ZF also has a wiki with a few tutorials. |
Templating | CodeIgniter includes a template parser class although in my opinion its use is limited as it does not support logic (e.g. if statements) in the views.However the CI recommendation is to use PHP tags in the views. | The Zend framework includes a Layout class designed to provide a common layout (or multiple layouts) for the entire website or application. It uses PHP tags for templating although it does provide an abstract view class which can be extended with a 3rd party template library. |
Components | CI has a lot of libraries and helpers to simplify the developer’s life.While it does have less of these than ZF, in the main, the usage of the CI variants is simpler. | ZF has a massive number of classes and components.These are well documented although the usage is usually a bit more difficult than in CI. |
Database Access | CI includes a database class which handles the database connection. The database class can be used for standard SQL queries creating, retrieving, updating and deleting data in the standard PHP way.CI also includes an active record class which is a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.Beyond simplicity, a major benefit to using the Active Record features is that it allows the creation of database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system. | Zend_Db and its related classes provide a simple SQL database interface for Zend Framework. It allows for standard SQL queries but simplifies retrieving the SQL results.It also includes an ORM using both the Table Data Gateway and the Row Data Gateway. These represent the database table and row respectively as objects and can drastically reduce development speed.The downside is a slight performance deficit when compared to the modified active record pattern used in CodeIgniter which does not use objects as extensively.Zend_Db can also model table relationships in PHP classes making database joins a breeze. |
Flexibility | CI is very flexible allowing almost all defaults to be modified. | ZF is simply a collection classes and as such any file or folder can be placed anywhere as long as the location is added to the bootstrap file. |
Validation | Data validation in CodeIgniter is handled via a validation class. A set of rules gets defined and assigned to the validation object.The validation object automatically validates the data passed via the URL or form. From there, the programmer can decide how that gets handled.The validation class can also help automate some of the process of setting error messages for specific fields. | The Zend_Validate component provides a set of commonly needed validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.In ZF, each validator is a separate class and the class is added to the data (like a filter) rather than the data being passed into the class like it is in CodeIgniter. |
Forms | The Form Helper file in CI contains functions that assist in working with forms.It aids in the generation of form fields although it does not completely eliminate the need to write HTML code. | Zend_Form simplifies form creation and handling. It handles element filtering and validation, escaping data and form rendering.Using Zend_Form, ZF can represent a form completely in PHP code including labels, validation and error messages. |
Performance | CI has about double the performance of the Zend Framework. | The Zend Framework is about half as fast as CodeIgniter. |
Testing | CodeIgniter has a unit testing class but it encourages mixing the test code with the actual source code so I don’t recommend it.A third-party extension for SimpleTest is available though.Using PHPUnit with the CI classes should also be possible. | The Zend Framework does not have a built-in unit testing class but the core classes use PHPUnit as their test framework and this can be extended to include any additional classes.Using SimpleTest with the ZF classes should also be possible. |
Internationalisation | No | Yes |
License | BSD-style | New BSD |
Summary
I was rather surprised at the performance difference (measured using apachebench loading the home page with one call to the database to retrieve four rows). I expected the efficiency of using PHP5 only features to make up for the extra size of the Zend framework.
The Zend Framework advantages include:
- The “official PHP framework”.
- My workplace is already a Zend “partner”.
- Full-featured layout and template system.
- Massive number of classes and components.
- Extremely flexible.
- More advanced database library.
- More advanced validation library.
- Internationalization support.
CodeIgniter advantages include:
- Extremely easy to setup.
- Lower learning curve then the Zend Framework.
- More accessible documentation.
- Concise syntax – The Zend Framework syntax is wordier.
- 100% faster than the Zend framework.
There isn’t any clear cut “winner” here in my opinion and we still haven’t chosen one yet.
Update: the benchmarks are now available
Related posts:
Great comparison, and I’m glad that you’re considering using ZF. A few points, however:
1) Set Up: We really don’t optimize for small size of the distribution archive. In fact, if you take a look in there, you’ll see about half of it is locale data in XML format. We plan to start building and releasing a ‘lean and mean’ distribution soon that I suspect will be no more than a few MB’s. But please keep in mind, if this is any measure of ‘bloat’, it is simply a reflection of how much disk space the framework takes up and possibly how many components we make available. Because all the components are loosely coupled, you can remove the components you’re not using to retrieve disk space as needed. Then again, I can’t remember the last time that I bothered to put any time in to paring down server-side software to save a few MB’s of disk space.
2) Documentation: How could we organize it better? I’m currently going through all the chapters to fix any spelling, grammar, technical, and style issues I see. I know that a few of the chapters are pretty rough English-wise since they were written by non-native speakers. Please send any feedback to wil@zend so I can keep it in mind while I’m doing this.
3) Database Access: Is there any noticeable performance penalty in using our more object-intensive approach when you take the heavy hit of a database query in to account? If so, let me know ASAP so I can profile and fix it.
4) Validation: I don’t understand what you mean by “the class is added to the data (like a filter) rather than the data being passed into the class like it is in CodeIgniter”. That description doesn’t match my understanding of Zend_Validate usage at all.
5) Performance: We get a lot of performance comparisons between ZF and other frameworks, but I have to say this is definitely one of the most generalized comparisons and sweeping conclusions I’ve ever seen between 2 complex sets of code.
You provide a basic description of your test case below, and honestly it doesn’t sound anything like a real world application. I hope you’re not taking the database calls themselves in to account, but I would *strongly* discourage making any kinds of conclusions based on such a simple comparison.
Performance benchmarks are hard. I’m not saying that ZF is slower or faster than CI in any definitive way; I don’t have the numbers from a sound experiment to back up such an assertion. But we do plan a full performance audit of ZF with comparisons against other major frameworks (CI may or may not be benchmarked) with full disclosure of methods. This will require about 2 developer months to finish with the direct help of our ZF architect and one PHP core developer. *That’s* how serious I am when I say it takes a lot to come up with conclusions about performance for complex pieces of software.
If you need some gauge before then, consider writing a small front-to-back part of your application using all the major features you expect to use in the final application on both frameworks and performance test it for major use cases. If you don’t have the time for that, then just let me mention now that ZF 1.6 and the quickly following 1.7 will both include significant performance enhancements.
6) Testing: Matthew, our ZF architect, has just completed a controller unit test harness that make testing controllers a piece of cake using PHPUnit. He’s mocked sessions, request and response objects, and- well- you might want to just check it out in the incubator: http://framework.zend.com/code/browse/Standard_Incubator/library/Zend/Test/PHPUnit/
7) General: Fortunately, you don’t necessarily have to chose one or the other, anyways! ZF components will work just as well within CI. It’s used very commonly alongside all PHP frameworks out there.
In any case, best of luck with whatever framework(s) you’re using!
,Wil
@Wil,
In response to your comments,
1)I do realize that size doesn’t matter (in this case) but the larger size did influence the time to set up the test to a small extent (I still had to download and extract the framework). Also, I do not think the size is a disadvantage, but I do think the effort required to set it up compared to CodeIgniter is.
2)In my opinion, the different sections are too isolated. A case in point was the database usage. I had to set it up in the bootstrap file, add the database object to the registry and retrieve it in the model. maybe it’s just me, but I couldn’t immediately deduce that from the documentation. CodeIgniter presents some of it’s examples (where necessary) in context.
3)Surprisingly, database usage did not affect performance by much. The benchmarks are here: http://www.avnetlabs.com/php/php-framework-comparison-benchmarks
4)Maybe that did not come out clearly but I meant that the CI way was more functional while the Zend way was more OO.
Both frameworks are good although I think we’ll probably end up using the Zend framework considering our Zend affiliations.
Pingback: PHP Framework ????? « Oceanic | ????
Pingback: Gildus» Blog Archive » Comparativa de velocidades de frameworks PHP
Pingback: Framework PHP a confronto : phpblog.it
Very informative and helpful for me in choosing a framework, thanks. Most of the other comparisons that I’ve been reading seem outdated, so it’s good to see a more recent one.
Hi
Great article – one of the best, and I’ve read a lot of them. I’ve been using CI for years and I like it a lot, but I also appreciate ZF. Right now we are starting the development of a custom PHP CMS (more like a framework geared towards integrators, not end users) and we decided to go with CI. I think that both frameworks are just great and that it finally is a matter of preference, driven by personal values and coding style. Our main issues with ZF were that it can’t easily be considered a RAD framework (it’s more like an API) and that it’s a bit cluttered. But hooking ZF into CI seems like a match made in heaven!
Good luck with your project!
I find without in-depth tutorials, preferably video tutorials, the learning curve for Zend will be too steep for PHP intermediate programmers. That’s my personal experience so far.
Most likely with so many frameworks available, Zend will be the one stay for many years, maybe even largely replace PHP code in many websites.
I am in the process of selecting the framework for a project of mine. So far CI fits the bill just nice because I want to have a small framework and build on that but a template system is a big requirement for me.. and after looking through the documentation for the template system in CI i can see that it is very very limited.
I haven’t done any in depth testing yet. So in your oppinion how difficult is it to integrate a third party template system, for example smarty, into CI.
CI 2.0 will most likely have a decent templating system, specifically because ExpressionEngine requires it, and since ExpressionEngine 2.0 will be based on CI, it has been said that whatever EE needs, CI will get.
In that regards, I’m really looking forward to a more full-fledged auth/acl implementation.
@scott,
Any idea when CI 2 is launching?
@paan,
It shouldn’t be hard to integrate smarty with codeigniter.
There are a lot of threads on the CI forum discussing it.
http://codeigniter.com/forums/viewthread/60050/ should help.
However, I have never liked the idea of including a seperate templating language when I can template with PHP (maybe because our designer gives me a complete XHTML and CSS layout and from then on he doesn’t touch the code).
Before MVC, I used the savant2 template library (which is also PHP based).
Yes, out of the box, CI templating is lacking but it’s not that hard to adapt it. I have implemented the same two step view pattern used in the other frameworks I’ve worked with in CI. I will do a post on this shortly.
Good luck in choosing a framework to work with. I must admit after working with Zend for a few weeks, I am absolutely impressed although I have had to ‘borrow’ one of CI’s classes (calendaring) to fill in the gap in the ZF.
A post showing how I use the two step view pattern with CI has been added as promised.
Check it out: http://www.avnetlabs.com/php/two-step-view-with-codeigniter
Pingback: Mrasnika’s Lair » CodeIgniter vs Zend Framework
IS there any plans to make ZF more rapid. I have been learning it for the past month and even with a background in OOP PHP i find it confusing once you get past basic blog.
As it is a collection of classes there is no standard way to set up Admin areas or your bootstrap and no “experts” on the main ZF sites can agree the standard practice. I know this was part of the flexibility aspect but surely some standardisation would make tutorials, 3rd party additions etc easier and quicker ?
Pingback: Bookmarks about Frameworks
Pingback: | ????@NET
Thanks for the post.I have translater this to chinese.
The Post’s url is
http://lee.kometo.com/index.php/archives/117
BTW:Seem Like,Your Blod can’t accept a tarceback with chinese and UTF-8 Charset.
This is testing for chinese.Just delete it.Sorry!
??????????????
Pingback: CodeIgniter vs Zend Framework : ???????????
Pingback: PHP Framework ????? - My Habari
good article
Pingback: A php framework is chosen | haraldringvold.com
Does anyone else have any experience with this?
Pingback: Blog.Chungyi.org » PHP framework
So, is CI the winner in that case?
what is the php framework that available more learning material and samples
@Nayana you should try CodeIgniter
CI’s user guide is easier to understand compared to ZF by the way. I think it’s good to use CI as the framework and then just borrow some of ZF’s libraries if needed.
HI guys,
I developed same appliaction with two frameworks.But zend only giving best performance….
Thanks
I had to disqualify Code Igniter from consideration due to the indemnity provision in the license. Some of my clients — particularly government or large institutions — just won’t agree to such a provision. I wish that Code Igniter didn’t alter the BSD license in that way.
Pingback: 重新审视 PHP 框架 CodeIgniter VS Zend | 五更起床,万事兴旺
Pingback: PHP framework comparison benchmarks | PHP Frameworks
CodeIgniter rules !
Pingback: PHP framework comparison benchmarks | Best PHP Frameworks | PHP Frameworks Reviews
Pingback: Re-thinking the web framework | *baby pink*
Thanks for this extensive write up!
I am a php newbie and am considering ZF or CI.
While CI seems easier to pickup I am worried about the fact that EllisLab has a flagship product of ExpressionEngine (a GREAT CMS!!!) I am worried that their focus, as well as CI developers, will be shifted in that direction more so then in the framework. After all, $ profit is a better motivator than vibrant community.
- What are your thoughts on future of CI especially that now it has already gone through one fork of Kohana?
In my mind, longevity of framework matters more than features that ‘here today, gone tomorrow’.
ZF seems to be older, well established and backed up by a team primarily interested into ZF.
Thank you for your thoughts!
To the post above– ExpressionEngine is built on top of CI. You can’t have EE without continued CI development. Stop spreading FUD.
No doubts in that, ZEND is the best framework. Zend framework will be very hard to learn as a beginner.
As a fresher “CodeIgniter” framework will be good to learn.
I was wondering what to use, Zend or CI for our project. The freelancer wants to do it in Zend and my friend is suggesting CI because, it is more scalable.
This post seems to favor CI, however all the comments are mostly supporting Zend including more efficient??
Now I cant make up my mind.
I’m working on developing a gaming site. Was wondering which is better. I’m inclined towards using CodeIgniter, but might read up more about Zend and CakePHP before finalizing on one.
What hasn’t been mentioned at all is that you can couple the Zend Framework classes with CodeIgniter. This really gives you the best of both worlds.
I used to use CakePHP, but have mostly been developing with ExpressionEngine lately and now that EE has been redeveloped using CodeIgniter have decided to dive into the framework. It offers a lot of promise over the next few years.
Good post.