Friday, May 6, 2011

php

0 comments
.

Notes on Choosing a PHP Framework: A Comparison of CakePHP and the Zend Framework

UPDATE:Parlez vous Français? Guillaume Rossolini has created a French translation of this article.
Are you considering using a PHP framework for your next project? If so, this article's for you. I've narrowed down my choices to CakePHP and the Zend Framework and have documented my findings here.
Four or five years ago I began researching PHP application frameworks. At the time, the pickings were very slim, especially when compared to those available to Java developers. On the advice of an ex-Coldfusion developer, I settled on the PHP port of Fusebox, the de facto Coldfusion framework. Fusebox 3 provided a convenient set of loose conventions for structuring applications, organizing code, naming files, and controlling flow. It served my development team well and applications we built with it are still up and running.
I took a two-year "break" from development and upon my return I found more PHP frameworks than you can shake a stick at. Now I need to find a solid MVC-based framework and after reading dozens of articles and completing a few tutorials, I've narrowed my focus to CakePHP and the Zend Framework.
Before going further, let it be known that my point of view is that of someone with plenty of application development experience but without a formal IT or CS degree. I can't go on about the merits of one design pattern vs. another. I do, however, understand the need for convention, the advantages of modularity, and the efficiency of easily repeatable processes.
Please note that symfony, Prado, Code Ignitor, and many of the other PHP frameworks all look quite capable of meeting most project needs. If you're a fanboy of another framework, please don't espouse it's merits here. I am, however, interested in hearing about your general experience in learning a framework, particularly in the context of your professional background.
Here's a comparison and a few conclusions after spending a bit of time with both CakePHP and the Zend Framework. Please note that my quality scale range is: poor, fair, good, excellent.

I hope to use both of these frameworks soon, but in the short term I'll most likely base an upcoming CMS project on CakePHP. I do plan on using the Zend Framework, if for nothing other than expanding my application design skills, PHP 5 OO knowledge, and understanding of MVC.
Conclusions and Recommendations


CakePHP: Hit the Ground Running Fast

If you are new to MVC, require PHP 4 support, want stricter conventions, or want powerful code generation tools, CakePHP is the choice for you. CakePHP's Scaffolding, Bake, and ACL scripts provide definite advantages when the need to quickly build an application arise.

The Zend Framework: A Model of Flexibility

If you know MVC, need more control over application design, or want built-in support for popular Web services, the Zend Framework is choice for you. The Zend Framework provides a greater degree of flexibility in designing applications that scale effectively in high-performance environments.
The bottom line is that both frameworks are rapidly evolving in response to user demands. Gaps in each are being filled and there seems to be no lack of demand for developers with skills in each framework.
Feel free to share your experience in learning any framework.

Comments

Zend framework is unusable with mysql

I just tried Zend framework for the last three days - it is unusable with mysql, because they don't know how to properly handle mysql query cache. If you try to port their QUICKSTART example to MySQL, you get nowhere with the error:
Message: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute
- only their proposed solution does not work. They claim it "only" affects MySQL pre-5.1.17, but im running 5.1.31 with same error.
Not properly supporting the worlds most used database vendor is inexcusable, and it has been this way (according to their error logs) for over a year. Epic Fail, Zend.
And yes, the error is caused by PDO, but using a faulty component in your framework is NOT an excuse.

To sum up: Their faulty framework just stole three days of my time. When they cant even have everything working in their quickstart example, no way am I going to chance it that they know how to do anything else
Conclusion: Stay away from Zend Framework!

Thanks

nice comparison. it helped me a lot :)

CakePHP Zend Framework Fusion

Hi You can use Cakephp with zend framework.

Congratulation

Great comparison dude, it's the simples and still most complete comparison I've seen, it helped me a lot to understand each framework and their differences, and I'm close on choosing my PHP framework now!
Congratulation on the quality of the post and tnx for the help!

Good...but outtdated

I would not use this as a fully reliable source for comparing ZF. If you take a look, a lot of the comparisons shown here would change drastically given all of the new features it has in the framework.

Usefull

very nice article

My experiences...

Hi all,
The article is a bit outdated, but the comment thread seems to be kicking so why not add to it?
I remember when my team and I arrived at the same two choices. We spent a good deal of time comparing the two, building dummy apps and production apps ( new clients make great guinea pigs ), held plenty of meetings and eventually decided upon the Zend Framework.
The article has a nice outline between the two, so I'd like to simply share my experience with this and perhaps pick up where the article left off.
The discussions eventually boiled down to where are we and where did we want to be? At that time we had built up a decent library in which to develop web sites and tools for our clients. We had a cluster of servers all running php4, so from a cost perspective it was cheaper to lean on Cake.
The problem with cake was two fold, first off the documentation at the time was really sparse and more often then not, outdated.

This presented us with having to spend additional time to learn and train the team, which would bring up the cost up. Additionally new staff and contractors would need more ramp up time when they came on.
Zend on the other hand was just coming out, and even though the documentation suffered at times like cake, we found it to be more consistent in its approach ( like the code ) and more to the point. There are assumptions that are made, knowing php5 and oo are mandatory. We liked the fact that we could find zend developers easily and bring them in to assist on projects that need additional resources. Heck, Zend even offers a cert for developers to test for.
We had little experience in the team directly with php5, but learning the next iteration of the core language we worked on sounded more fun, not to mention better for our own skill sets, than learning to work within Cake and its conventions.
A downside, at the time, was that Zend provided no modularity. By that I mean, we couldn't run instances of zend as a collection of applications, at least not with out giving up some performance. We decided this was acceptable and used it as an opportunity to develop our own framework.
Also we decided that we needed more power between our app and the db, so after a bit of research, we landed on phpDoctrine. Doctrine is an ORM ( Object Relational Mapping ) library. Again, at the time zend had little feature set with their zend table and db... since then it has improved.
Side note on doctrine:
The doctrine code base is a robust abstraction and object mapping layer for php applications. For basic interactions with a db, mysql, it is overkill. Using this library will provide you with a wide range of functionality, much greater in breath then what zend provides. This comes with a price though, the objects are resource intensive and if not used properly can bring your application to a crawl. The documentation on this is not very well done, but the examples are well shown. There's not much of a community so you should be prepared to find your way in the dark at times. ex: Cascading deletes didn't work on MyISAM tables, so we had to patch that until they did it themselves. Ok enough about doctrine...

Right now our framework is being used primarily as a cms for public facing sites, and as a framework it is still in its infancy ( client work took first priority ).
The Zend Framework turned out to be the best option for us. As zend grows we are getting some very solid components to work with. If you haven't yet, check out the latest version release a short while ago, 1.8 as of writing. Zend has some nice interfaces for hooking into Amazon's "cloud" and fantastic code generation ( No more template approaches for automating new code, such as models or modules. There are a few others, so check it out and see for yourself.
So what is the better solution Zend Framework or Cake? Well that depends on you, your own needs and goals. Do you need to bang out a quick project that while having robust code at your fingertips while giving you the power to create customized functionality, Cake may be your best bet. Do you need a code base to build from on an ongoing basis, Zend may be the choice for you.
Find out, and post your experience... maybe this article will last a few years.
Cheers and good luck!
dev_head
San Diego, CA
Senior Developer

A blog post in a comment

@dev_head, thanks for sharing your experience in such depth here. Writing a custom framework certainly allows you to optimize for your environment and other requirements, but I shudder to think about the extra work it takes to maintain.
Since writing this article, I have yet to write a complete app with either CakePHP or Zend, but I've kept up on Zend releases and have been really impressed. Yes, Zend_Tool is providing something akin to CakePHP's scaffolding features.

In my experience I chose

In my experience I chose CakePHP over other frameworks
because its fast to learn and because of its strict conventions it made my code very readable. The documentation are ok and most of all there is an IRC Channel #cakephp on irc.freenode.net
which is very active.
And also if ever there is a need to use libraries coming
Zend Framework you could also use them in CakePHP.

Update needed

You need to update this comparison especially because Zend Framework DOES support JQuery and Dojo JS Frameworks

Thanks - Going with Cake

You've confirmed my thoughts on frameworks for php. I'm going with Cakephp because it just feels right. Zend has always given me the creeps for some reason. Thanks for the article!
Mike

Thanks for this article.

Thanks for this article. This help me those the right framework for my work.
Keep up the good work.

I agree, that many framework

I agree, that many framework developers are not aware of performance issues. A reason for that may be the availibility of byte code caching or other tools to store information (e.g. application caching, memcached, …). But this is not true for everyone. Especially, the APF is designed for best performance (see http://adventure-php-framework.org/Page/103-Yii-vs-apf/~/sites_demosite_...). Combined with a rich featureset (see http://adventure-php-framework.org/Page/088-Why-apf/~/sites_demosite_biz...), the APF is worth a try!

Thanks

Thanks for this article.
Good comparison and straight forward arguments.
Best regards

Best comparison I read so far!

Thanks for this article. This is the best comparison between ZF and Cake I read so far.
Keep up the good work.

Great Comparison, Thank you.

I finally broke down and decided to pick up one of the popular frameworks out there. I had just started writing up a similar comparison when I found your article. Thanks for saving me the time!
I've chosen to go with Zend primarily because of its industry backing. I mean, PHP is made by the Zend guys... seems solid to me!
Anyway, cheers!

Cake PHP is much better than

Cake PHP is much better than Zend although it doesn't support PHP arrays.

I've used Andromeda DB

I've used Andromeda DB Framework and its awesome!

Great Article!

Thanks for the review! Appreciate the time spent in listing down the differences for a php newbie like me.

ZF is licensed with "new" BSD

Just in case someone wonders, I had a quick look at the documentation and it says athttp://framework.zend.com/license that they use the "New BSD License" where the third "advertising clause" from the original BSD license is missing.
That makes it fully compatible with the GPL as written here:http://www.gnu.org/philosophy/license-list.html#GPLCompatibleLicenses
Thanks for the good comparison though, I was wondering which framework to use when building an addon for the BIGACE Web CMS and ZF won, because its easier to integrate into an existing app.

a great thanx

Hello! you know, I'm a beginner at this job, so i just started learning about php and how it works, but your article on PHP Framework was really helpfull for me... that's why i'd like to say a great thanx to you!

Flexibility

For those who value flexibility and freedom over forced convention in frameworks, I recommend having a look at Kolibri. While it provides sane defaults with no/minimal configuration, you are for instance free to use the template system you prefer, whether it is XSLT, Smarty, pure PHP or something else entirely.

Another criterion: easiness to learn

Thanks for your great comparison!
I made a short review of the main available frameworks, and my final selection ended with ZF and CakePHP. Your comparison helps me to learn more to choose one from the other...

But there is still a missing criterion in your comparison which I would find very useful: how easy was it to learn each of these frameworks ? According to your experience, which one requires the least time to get confortable with ?
Thanks in advance.

No comparison.

You can use Zend inside a Cake app. You can't the the opposite.

Codeigniter seems friendly and concise to beginners

I am not a php geek. when I started looking in search for a framework to start with, I was really impressed with Codeigniter at the first shot. It's simple and has a great documentation. To begin with a PHP framework, its really a great decision to go with Codeigniter and when your need demands more, you can go for another framework or can still checkout Codeigniter libraries and forum.

To be honest, I think the

To be honest, I think the zend framework is more flexible..

I like CakePHP better than

I like CakePHP better than the Zend Framework. If you actually take a look at both more in depth, you'll find that Zend is not as much of a PHP framework as CakePHP is. But don't take my word for granted, I'm prolly biased since I've been using Cake ever since it came out.

About PHP Framework

Thanks alot, this is a great article and resource for me. A really good discussions about different php frameworks for web. This is what i was looking for. i bought 3 books on frameworks for PHP, and learning different aspects of PHP4 and into PHP5.

good

Very nice article thank you very much...

Thanks for your great

Thanks for your great comparison!
I made a short review of the main available frameworks, and my final selection ended with ZF and CakePHP. Your comparison helps me to learn more to choose one from the other...

Excellent comparison

About two years ago, I started looking at CakePHP, and the documentation was absolutely horrible - sections of info were missing, the docs were out of sync with the code, and I had difficultly obtaining help from a human with seemingly basic CakePHP issues.
I basically gave up on CakePHP in favor of CodeIgniter, and never really looked back.
Out of curiosity, I started digging around for CakePHP info again, and I can say their docs are now light years ahead of where they used to be. The only thing that bothers me is their examples/tutorials still seem to be the ones from two years ago, and some of the info is incorrect or deprecated.
My problem with Zend framework is that sometimes plain ol' raw PHP is better than a class extending a class extending a class as a wrapper of a PHP function... Though I suppose all frameworks do that from time to time, for the sake of modularity.
Anyway, excellent comparison. I hope you'll write a follow up at some point once you've developed a project with one of the frameworks.

Thanks, this was a great

Thanks, this was a great article and spawned a good discussion on php frameworks. I was looking for this exact info.
I have dabbled with CI a little, but I have bought in to the whole php5 oop thing, so I was looking for something that could leverage php5 without worrying about having to support php4.

fabulous article, did you know?

Just wondering if you are aware that the Joomla 1.5 CMS has MVC include as part of the framework

Most suitable

I think the major doubt inside the decision of choosing frameworks is which one fits better on some specific project.
I have doubts on that, and no comparison I have found show me clues that would point the solution...
For example, which one would be more suitable for multiple projects with common data, sharing common database?
Is it possible to say what cases CakePHP will work better than Zend Framework? As well the opposite?

No comparison is going to answer this question

No comparison is going to answer this question for you completely. Hopefully these types of comparisons can shed light on a few points that pertain to your project.
There are too many variables, considerations, and preferences. I encourage you to download and try those frameworks your considering.

Cake has the edge on testing

One big selling point for CakePHP is that its test framework is Simpletest, while ZF uses PHPUnit. The difference between these two is that simpletest has better mock object support.
This is important if you test first, then write code--which you really should try! it's liberating--because your controller frequently interacts with model (database) and view, so it's nice to know, by using a mock database/view, that your controller is doing exactly what it should. In other words, you have to have the mocks in order to fully test (i.e., define by means of tests) the controller's API.

Basic search

tells eveything. Google results of cake are around 3.700.000 pages. Zend are around 637.000 :)
Also Cake is now version 1.2. Imagine the pain and suffer during all this version staging period.
I would like to go with mature framework.

Peace
Kunth

"Google results of cake are

"Google results of cake are around 3.700.000 pages. Zend are around 637.000"
17th of August, 2009. www.google.com
Results 1 - 10 of about 4,510,000 for cakephp
and
Results 1 - 10 of about 6,370,000 for zend framework
Seems to be its obvious, what is more supported nowadays..

Volumes of searches really

Volumes of searches really tells you absolutely nothing. I found it best to try out the basic tutorials on the frameworks and see what you like the look of for your project.
Also - I can't say I have found Zend's documentation 'excellent' as it reports above - which is another reason I have chosen Cake to try for the next project.

Thanks, this was a great

Thanks, this was a great article and spawned a good discussion on php frameworks. I was looking for this exact info.
I have dabbled with CI a little, but I have bought in to the whole php5 oop thing, so I was looking for something that could leverage php5 without worrying about having to support php4.

Searches narrow down the list to test

I disagree. I think searches shorten the list of things to download and try.

Something to be said for quality

Quantity and age are certainly not representations of quality or appropriateness. I encourage all who are evaluating PHP frameworks to dig a bit deeper. I've been spending quite a bit of time with the Zend Framework since writing this comparison and have been please with the results achieved so far.
ZF has announced a partnership with the Dojo JavaScript Toolkit and the upcoming ZF command line tools. Each of these announcements demonstrate that the ZF is quickly bringing it's feature set up to that of other PHP frameworks.
Another point that I didn't include is training. The ZF is backed by training provided by Zend.
All I'm trying to say is that folks should dig a bit deeper when deciding what might work best for them.

Freedom of choose

One of the js tools like prototype or jquery dojo or motools. This is totally related to my problem domain. That's why we have bunch of frameworks and we decide one or another. I am not exciting to hear Zend Dojo cooperation. We saw a kind of conquer and dominate market sh*t before.
Just be a coder, check code to understand that;

SomeOne.prototype.change = your_life

I can choose!

One of the js tools like prototype or jquery dojo or motools. This is totally related to my problem domain. That's why we have bunch of frameworks and we decide one or another. I am not exciting to hear Zend Dojo cooperation. We saw a kind of conquer and dominate market sh*t before.
Just be a coder, check code to understand that;

SomeOne.prototype.change = your_life

I can choose!

One of the js tools like prototype or jquery dojo or motools. This is totally related to my problem domain. That's why we have bunch of frameworks and we decide one or another. I am not exciting to hear Zend Dojo cooperation. We saw a kind of conquer and dominate market sh*t before.
Just be a coder, check code to understand that;

SomeOne.prototype.change = your_life

Several things about Cake

Just my 2c:
Compatibility: Cake will switch to PHP5+ only in 2.0 (according tohttps://trac.cakephp.org/milestone/2.0.0.x)
Configuration: Cake has a default configuration in a PHP file, but there is nothing stopping you to override it and read the configuration from an XML file or database or whatever you want.
Caching: I believe Cake supports more than just "file cache":www.cakephp.org/files/OCPHP.pdf
Very nice comparison though!
Cheers!

Nice article!

A great comparison between the two frameworks Chad! :-)
Inspired by your comparison, I wrote a similar article/comparison on CodeIgniter and Kohana.
Hopefully some people will find it useful.
Cheers,
Fred

Great comp!

Yeah i have to say it's a great comparison. I always used Cake Php, but i start thinking about trying igniter, as the documentation seems to be way more available. Having good info about our php framework is almost 50% of how we're going to like it, it's some time a pain to try to find out everything by yourself. Anyway, i still have to say it's two great framework ;)

Try Django !

I originally come from the PHP world but have been using Django (a python web framework) since a few months. I am really impressed by the quality, the features and the extensibility of this framework !
Concerning PHP, I am a big fan of CakePHP.
A useful start to have an overall view of PHP and non PHP (Ruby, Java, Python) frameworks :

Good Review

Excellent review and very fair. I think you found the main differences in the MVC and configuration/convention differences. Also the ZF is extremely loosely coupled so that it's trivial to integrate most components (such as Zend_Search or Zend_Pdf) into another application.
One minor point is that the ZF also supports PHP arrays for configuration, though my personal preference is INI.
Regards,
Rob...

0 comments:

Post a Comment