views:

298

answers:

5

There are tons of PHP frameworks out there; some are pretty decent, others seem bloated and unnecessary. After watching Rasmus Lerdorf's presentation on PHP performance at Digg, I'm somewhat more concerned about the performance of the frameworks that I choose for building my applications with.

Two of the most popular frameworks that I'm aware of are CodeIgniter and CakePHP. From what I understand, CakePHP is a terrible resource hog. What about CodeIgniter? I hear that Zend Framework isn't all that slim, either.

Are there other (more performant) frameworks that I should be interested in? Would it be better to simply not use a framework at all? What considerations should I make towards choosing a PHP framework?

+3  A: 

IMHO, the advantages of using a framework far outweigh the disadvantages of any overhead costs that may come with it. Of course there are always exceptions to the rule, these being:
- The project is small enough to not warrant a framework
- The framework itself is horribly designed

But for the majority of cases, you shouldn't worry about it. I've been using Symfony (versions 1.2 & 1.4) on a number of projects, and haven't once thought "this is too resource heavy". I will gladly sacrifice some resources in exchange for all the tools a framework provides that makes my life easier, and the job take less time ;)

Arms
There's another exception. The project has a high enough traffic level to warrant extended developer time in exchange for less server resources (This is a very high level, but it's a valid exception)...
ircmaxell
I think it's always cheaper to throw more hardware at performance issues than paying developers to optimize code, and then the increased maintenance costs incurred because of less readable code. Obvious and easy steps like caching should of course be done, but besides the obvious stuff.
Jani Hartikainen
It's not always cheaper... When you have hundreds or thousands of servers, dedicating a programmer to performance issues is going to be far cheaper than throwing more hardware at it. Oh, and since when does not using a framework === less readable code? We're not talking about a junior developer writing the entire application (I'm assuming a competent developer on all sides)...
ircmaxell
Look at FaceBook. They are on PHP. ;) HipHop appeared only some time ago and before it did, they were satisfied with PHP. Why you don't? :)
FractalizeR
+7  A: 

you might want to look into the lightweight frameworks category. there's fat-free, doophp, limonade, etc. they're lightweight, but not less-powerful than you might think. don't rely on published benchmarks. instead, benchmark against your own objectives.

stillstanding
+1 for the links. :)
banzaimonkey
+16  A: 

Using a framework or not using a framework means you're making a choice between

  1. Default Application Performance under load

  2. Speed/Stability of Development

If you decide not to use a framework, you still need to do the things a framework would do. You're just coding them yourself in raw PHP, or developing your own framework that can remain lightweight since it only has to do what you want it to do, and not what the world wants it to do. You will get better performance, but you'll spend more time developing and debugging that code that a framework handles for you automatically.

What a framework buys you is speed in development time. You don't have to write out long complicated SQL queries, or debug someone else's long complicated SQL queries. You just need to create a table and instantiate a model. You don't need to decide where you're going to escape your SQL paramaters, because the framework defines where that happens. You don't need to get into huge political fights over where the business logic vs. presentation logic goes, because the framework defines this. A framework remove the need from having a system developer on your team, or removes you from having to think about/waste time on system development. You can get to coding your application faster and get measurable, visible results sooner.

Here's another way to think of it. PHP Frameworks are slower than PHP, but PHP itself is slower than C. Why not write your application directly in C?

There's no right answer here, it's one of those software engineering/development questions that's a matter of what your current situation demands. The default choice of the industry these days is to use a framework, because if you don't your competitors will release an application that has slower PHP processing than yours, but hits the market three months earlier.

Finally, one last thing to consider from that talk. Rasmus said that Most of the time the perceived performance of your application is in the frontend. Both the Javascript code and how the browser is caching the requests it makes back to your server. PHP is an awful, horrible language that's rarely the bottleneck. When it is the bottle neck, you can usually make a few adjustments (opt code cache, focused refactoring) that will remove the performance bottleneck.

Alan Storm
I really enjoyed reading your text and couldn't agree more. Nice work. +1
stefan
A: 

As far as I am aware CodeIgniter is a little bit of a lighter framework. Most people I know use CodeIgniter vs. CakePHP. But I've been using CakePHP for a number of years.

If you really worry about scale, take a look at using a NOSQL solution like MongoDB or CouchDB from the onset. (I use MongoDB and for most applications mongo can replace MYSQL). Other than front end, database calls are often what slows you down.

Another thing to consider is having a delayed worker queue. For this like processing images into thumbnails it is often best to have a separate process dealing with this and avoid having the user wait.

Nearly all big scale websites use caching. Database caching and HTML caching. You can look at MEMCACHED wich nearly everyone who's big uses and stores your cache in memory. MongoDB also has a reported memcached like speeds when calling data.

Like everyone else says on here, it's mostly not the framework that doesn't scale. It's your whole architecture. I haven't looked at the other lightweight frameworks but if you are picking between CakePHP and CodeIgniter, I would personally go with CodeIgniter. Also just make sure you continue to refactor your code over time this will give you the opportunity to make changes that speed up your app.

3en
A: 

I've only used CakePhp in anger over a period of several years. Yes, it is big and may seem bloated but, to be honest, I think that if I had used any other framework it would be as big by the time I've added everything that I have and use with Cake.

Speed-wise, we're talking small fractions of seconds difference between the contenders. Optimising your site using tools like Yslow and gzip and, of course, sensible design, will realise greater improvements than the choice of framework.

http://www.grasset.es is a site I built about 4 years ago with Cake. It's big and comlex, but I don't think it's slow.

Leo