A Comparison of PHP Micro-frameworks
I have a few projects that need PHP server side. After a few trials to write classes myself I realized there must be wheels already invented (“frameworks”). After some research I found myself prefer micro-frameworks strongly over some full-fledged frameworks. And further research did give me some interesting names.
The first thing to mention is that I found a nearly full list of PHP micro-frameworks (though the data not quite up-to-date) at http://phptrends.com/category/9
My Requirements
It’s always best to be clear what are the must-have features, and what are the bonuses.
For my projects, the basic, overlapping functions are
- User log-in, register, password retrieval functions
- Cron for scheduling task
Some bonuses can be
- OAuth2 client support (even as an extension) for facebook, Google, Microsoft account log in
- Caching (strong bonus)
- Database API
- built-in AJAX responses (weak bonus)
- Template support
Not quite attractive but may be nice:
- JSON support (not attractive because PHP can handle it very well)
Baseline: while I can write code to cover all my needs, using a framework should substantially reduce my workload and increase levels of maintainability and security.
General-Purpose Micro-frameworks
Code is from each one’s official documents unless noted.
1. Slim
Available at http://www.slimframework.com/, Slim seems to be one of the most popular players in this category. The hello world looks simply. You just need to define the routes and run the object.
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo \"Hello, $name\";
});
$app->run();
The object-oriented style is a minor bonus for me.
It looks like there is an example for facebook integration: https://github.com/tuupola/slim-ar-facebook
Another rough example is at: http://help.slimframework.com/discussions/problems/824-facebook-api-using-slim-framework
Notable: support for caching, error handling, and middle ware. Written in object-oriented style.
Last Update: Nov 29, 2013
2. Flight
Available at http://flightphp.com/
require 'flight/Flight.php';
Flight::route('/', function(){ echo 'hello world!'; });
Flight::start();
Notable: supports JSON requests/responses. Caching.
Last Update: Jan 17, 2014 (and the update is too frequent to be considered a bonus in my opinion)
3. Wave
Available at http://www.waveframework.com/
Much more powerful. What makes this framework notably different from others is its built-in API handler functionality.
Notable: MVC; caching; XML, CSV, JSON, HTML, native PHP and other data formats as output; user permission control; built-in security layer; ajax handling; provides Nginx conf file besides Apache .htaccess.
Last Update: Aug 18, 2013
4. Fat-Free Framework (f3)
Available at http://fatfreeframework.com/home
Notable: caching; ORM data mapping (best if one needs to transform from one db product to another); plug-ins; SMTP wrapper; OpenID support; singleton support; Nginx support.
I have been using F3 for a while and am happy with it by far. It is simple, and does not exert much restrictions to you. The speed is also impressive. I have made Opauth work with f3 so OAuth is also done.
Last Update: Mar 19, 2014 (not frequently but shows the developer’s steady effort to this project)
5. Jolt
A sample entry program in Jolt is like
$app = new Jolt();
$app->get('/hello/:name', function ($name) use ($app) { echo \"Hello, $name\"; });
$app->listen();
which looks similar to the other ones.
Notable: caching; error handling; middleware (sounds like a trimmed Slim…)
Last Update: Jan 14, 2014
6. Aura
It is not a typical PHP framework, but “fully decoupled libraries, and truly independent packages”, as its homepage states. However, it has a Aura framework built in on Aura packages.
As of Feb 06, 2014, it is in beta for v2. Considering my time frame, I am afraid I can’t wait for its release version.
7. Hydra
https://github.com/sandulungu/hydra
Notable: “strong” security in its feature list (don’t know how to verify at this stage); twig engine engine.
Last Update: Jan 2013.
8. Epiphancy
https://github.com/jmathai/epiphany
Epi::init('route');
getRoute()->get('/', 'home');
getRoute()->get('/contact', 'contactUs');
getRoute()->run();
function home() { echo 'You are at the home page'; }
function contactUs() { echo 'Send us an email at [[email protected]](mailto:[email protected])'; }
Looks like it got a new update on its Github repo on Dec 25, 2013.
9. Popcorn
The fully-featured Pop framework has a tar ball of size 1.9MB. But the tar of its watered-down Popcorn framework has a size 39KB.
Didn’t check it carefully so cannot comment now. At a glance it offers what other frameworks offer.
Last Update: Jan 27, 2014
10. Silex
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function($name) use($app) { return 'Hello '.$app->escape($name); });
$app->run();
Silex uses Symfony2 components, and Opauth has Silex support.
11. FRAPI
12. Phalcon
Written in C as a PHP extension, Phalcon eclipses others with its supreme performance but also offers the functionality a typical PHP micro framework can give. What it is missing is the utilities libraries like the Minify (in F3, this is part of Web class) and Image handler classes as seen in Wave and F3 frameworks. However, Phalcon provides much better helper components for data processing.
In one sentence, if one has time and energy to build the components he / she needs, and foresees the need for performance and scalability, choose Phalcon.
Comparison
Wave framework and Silex seem the ones that provide most functions.
But it is much easier to implement small projects using f3 (Fat-Free Framework) ΓÇô things seem to be “just enough”.
Other Job-Specific Micro-frameworks
1. Medoo
An one-file framework for database operations. First impression: slim and sexy.
2. php-login
A framework (from professional MVC to one-fine package) specially for user log-in operations.
3. opauth
Opauth provides a generic layer for oauth providers. Compared to Hybridauth to be mentioned below, it is much smaller in size, but the code needs a major renovation (already in progress in wip-1.0 branch). It has some examples to embed opauth in major PHP frameworks including Slim.
4. oauth-php
http://code.google.com/p/oauth-php/
5. HybridAuth
http://hybridauth.sourceforge.net/
At first glance, it looks like the ultimate social connector framework. It supports connection to more than 30 Oauth websites, and has plugins for CodeIgniter, Zend Framework, Yii, CakePHP, and Symfony frameworks available. However, I will need to do some work to have it co-work with my favorite micro-frameworks. But it seems the work is worth it.
Some non-PHP frameworks that may relate
This section goes somewhat off-topic, but may be useful if one is building mobile apps.
SocialAuth
https://code.google.com/p/socialauth/
SocialAuth is a generic OAuth consumer for Android projects.