To be honest, I’m a bit fed up with Drupal lately. We’re stuck with an ever-growing fat Drupal6 site, and the monster doesn’t get easier to maintain. The question isn’t if we will upgrade, but to what we will upgrade. The logical upgrade to Drupal7 will be enormous because our website has over 150.000 lines of custom php-code (not mentioning css, js, themes). So moving to Drupal 7 or creating something entirely new based on a framework… I don’t dare to say how much difference in time it will make, but I do know that the new thing must be a giant step forward to what we have now.
Why moving from Drupal to a Framework?
As much as I love Drupal, the thing is… a lot of modules do kind of what I want, but they don’t do exactly what I want. Customizing a contributed module sometimes takes me as long as I would write it myself. Especially when there’s little info in the README-file or when there are hardly any comments in the code. To give you an exampe: it’s faster to lookup the url for the admin-page in the menu-hook, than to find it in the documentation or in the navigation.
Plus, what irritates me the most. When you have +75 modules, +100.000 nodes and +10 currently logged in users, the thing gets slow.. slooowww! Even with advanced caching tools such as Memcached, view-cache or Varnish, the thing still goes slow, even on a dedicated server. No wonder: every hook is checked for each and every request.
So I’m looking for something faster and more OO-like. I have a C#-background and the way classes are mimicked in php (including inheritance, namespaces) is simply terrible. I’d dare to say Drupal goodbye, as long as Drupal 8 isn’t released an is more decent.
My comparison of PHP Frameworks
Pfhew, long introduction, but here’s my research on PHP-Frameworks. Briefly, a framework provides a set of functions and classes to help developers write code faster and more structured. Most of them implement certain design patters, of which MVC is by far the most popular. The aim of MVC is to seperate the database-talking-code (Model) from application-specific code (Controller) from html (View). It also features a URL-mapping system to set “clean url”-rules and to separate the code-files from the actual urls (eg: /bootstrap.php shouldn’t be accessible through a browser).
Some devs use the bootstrap of a CMS as a framework-starter (like my RSS-boostrap), but it should actually be the other way around: a CMS should be build on a framework. Drupal8 will (maybe) rely on parts of Symfony2, but that won’t be out till 2014.
I start off with a framework that isn’t PHP.
- Django is a kind of MVC framework aimed for webdevelopment, based on Python (not PHP!).
- Working with Django requires Python-knowledge. Python is a strong reliable fully object oriented language.
- Installation/execution is through command line.
- Django was developed by World Online (a Kansas newspaper) and is now open source.
- Installation on a dev-server is pretty easy but the actual deployment requires a study (it isn’t just copying files).
- Django has a CMS called Django-CMS. It’s pretty lightweight and provides basic functionality for creating and editing. But, the installation requires some configuration and Django-knowledge.
- Django is a rather fast framework.
- Django has a default “admin system” you could use as a backend. It can create/edit/delete objects and save them in the database.
I was eager to start with Django, but I don’t have any Python knowledge and the whole deploy process seems rather complex. For a complex website like ours, a total new language doesn’t seem the best option to me.
- Each website needs a different Kohana “installation”. However it is just a server setup check. Not difficult or special.
- Kohana works with the MVC-concept incl. mapping.Configuration is mainly in application/bootstrap.php and modules/…/database.php
- Kohana gets criticized for its poor documentation. “Look it up in a code” appears to be the way to find out.
- Lightweight, should be fast.
Kohana appeals to me. It all seems nice and clean, but reading negative reviews about dev-time and poor documentation makes me unsure.
- A new framework, created in C to work togheter with PHP. The big difference here is that the framework isn’t built on PHP, but on C. This makes Phalcon the fastest framework out there [systemsarchitect.net].
- However, very few projects have been realised in Phalcon (here’s a list of rather poor live examples [github.com])
- I somehow didn’t manage to get Phalcon installed (and couldn’t find any Google help).
I think the support and documentation currently lacks because this framework is still new and doesn’t have a big community (yet). It’s also unclear how long the current version will be supported. Also, debugging will eventually require C-knowledge.
- Bigger than Kohana in size, documentation and community.
- They don’t claim to be MVC, there’s not really a Model but there is a View and a Controller.
- It’s important to use Symfony v2 (not v1), because v2 is written from scratch to fully support erm MVC.
- HTTP-reverse-proxy-cache, Varnish functionallity, various cachable blocks on one page. This is a huge plus.
- Various benchmarks say Symfony2 is slower for small websites because of the weight of the framework. A lot of code must be executed for each request. (similar to Drupal)
- Drupal8 will include parts of Symfony2 [davetech.com], so it might add up your Drupal-knowlegde in the future.
Hmm, Symfony eyy. However, the fact that it isn’t lightweight scares me here. It isn’t the intention to have a site as slow as our current. Also, the “quick tour” didn’t convince me.
At this time, I’m getting a bit lost in all these frameworks and still 5 to go. It annoys me that the PHP-community isn’t behind 2 frameworks with both different goals. Instead we get a dozen frameworks all doing not just that what we want.
They all promise you heaven, but. It’s more useful to look up reviews (like this blog) than the marketing you find on the actual site. The real valuable information comes from the users, not from the creators.
- Laravel looks more like marketing than anything else. Some self-confidence is good, but Laravel is way over the top about itself. But Laravel got quite some good critics, so I thought it’s worth checking out.
- Laravel needs Composer to be installed and Composer requires a change in sohosin.ini (that will be shared-hosting-fun!). It also requires PHP >5.3.7 and the mcrypt extension, which is a good thing, because PHP 5.3 is an improvement on the previous versions.
Apart from that, the installation is pretty simple:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer composer create-project laravel/laravel website-name --prefer-dist cd website-name composer install
Your webserver needs to point to the /public folder in your website-folder. I found a valid nginx config here [laravel.io]. Apart from that, you need to give the webserver permission to write to the folder /app/storage and its underlying folders.
- Laravel also contains a command line interface called “artisan” as I quote “is driven by the powerful Symfony Console component.”
I must say the quickstart manual is pretty straightforward and logic. So far, it’s the only framework that didn’t hold me back for some reason. The database model and the OO-model don’t have to be exactly the same and can be specified apart, which I think is a good thing for flexibility. So far, this is my choice.
Silex & Slim
Silex and Slim are so called “micro-frameworks“. In other words: lightweights, but with only few features. Because I search a framework for a big site, I skipped those. But they might fit for your website. Both ought to be very fast (for PHP).
Zend & CodeIgniter
There are 2 other famous frameworks around:
Zenn Zend (from the creators of PHP) and CodeIgniter. I didn’t check them out because I found only few articles that were positive about Zend and CodeIgniter was sufficient 7 years ago but is becoming a dinosaur. [Update 09/01/2014: David in the comments mentions: “It’s the newer frameworks that are more likely to go the way of the dinosaurs.“, good argument. ]
CodeIgniter was forked into Kohana and FuelPHP.
In the end it comes down to this: lightweight frameworks (Django, Phalcon) will be faster, but will require a bigger investment from the developer. Full sized frameworks (Symfony, Zend) will have more out of the box functionality, but will tend to be slower (certainly for small sites).
Keep in mind that PHP is pretty broken by default [veekun.com]. Frameworks provide a way around to deliver professional code, but you keep working on an inefficient stack. That’s why both Phalcon and Django appeal to me. For this project, the Django learning curve would be too high, and there aren’t a lot of Python-jobs around here. If for some reason I have to move away from the project, I want my colleagues to be able to find a new dev and there are more PHP-devs than Python-devs around (in Belgium). I also have 150.000 custom lines of php-code, and I want to recycle at least some code. Python would probably double devtime.
I will give Lavarel a serious try. It seems to be well supported, not too light-weighted but not a monster either. More soon on this blog.
Codeignitor: Phil Sturgeon (contra)
[[ UPDATE 09/01/2014: With the recent popularity of this posts, there is some criticism about missing frameworks and the lack of information about Zend and CodeIgnitor. I must say that these are my personal notes from a midweek research for a certain project. I didn’t exclude certain frameworks on purpose. Especially Yii and CakePHP should have been included. ]]