Before I can start talking about PHP RESTful micro frameworks, let me first say that I am first and foremost Java developer. At the same time, my personal and official job also requires of me to work with PHP, from time to time.
 
It was never my intention to write an article about this topic. A purpose of this blog is to help mobile developers working with JavaScript; PHP was never part of it. But as things go I made a decision to write a rather complex set of jQuery Mobile tutorials that required server side communication. My first thought was to use Java Play Framework. This plan backfired when I found out that a lot of my readers were PHP developers.
 
Everything mentioned before urged me to switch to PHP but at the same time I was required to spend some time searching for the best replacement for the Play Framework. This article should showcase this search.
 
I will try to be as much objective as I can. Before I chose these frameworks, I spent a lot of time playing with everything available attempting to find a perfect one. Don’t get me wrong, this doesn’t mean other frameworks are wrong or inadequate, as you will see, my decision was hard, and it took time.
 
 

Note: If this tutorial was helpful, need further clarification, something is not working or do you have a request for another Ionic post? Furthermore, if you don't like something about this blog, if something is bugging you, don't like how I'm doing stuff here, again leave me a comment below. I'm here to help you, I expect the same from you. Feel free to comment below, subscribe to my blog, mail me to dragan.gaic@gmail.com, or follow and mention me on twitter (@gajotres). Thanks and have a nice day!

PS. If you want my help, if possible (even if it takes you some time to do that), create a working example I can play with. Use Plunker for AngularJS based questions or jsFiddle for jQuery/jQuery Mobile based questions.


 

Table of Contents

 
 

Recomendations

 
A lot of my readers asked me this question, and I’m sick of repeating it over and over again (smiley face).
 
I will recommend these four frameworks:
 
  1. Silex
  2. Slim
  3. Lumen
  4. Phalcon
 
If you require an explanation, scroll down and read my reviews.
 

Intro

 
Before I start take a look at a list of my chosen ten, in alphabetical order:
 
 
 

1. BulletPHP

 
Introduction date: 2012
 
The Bullet is a rather newer addition to PHP micro-framework community with a unique approach to URL routing. It helps you quickly create REST APIs and web applications that automatically conform to the requirements of the HTTP specification. Unlike most of it brethren Bullet is a resource and URI-oriented and comes pre-loaded with powerful HTTP features like content-negotiation and caching.
 
Fundamentally that means instead of defining a full path pattern or a typical URL route with a callback and parameters mapped to a REST method (GET, POST, etc.). The Bullet can parse only ONE URL segment at a time, and only has two methods for working with paths: path and param.
 

Links

 
 
Official Site Documentation Installation, Working Example
 
 

Pro

 
  • Its unique design prevents a lot of code duplication. Nested closures are crucial to how Bullet works; they work similarly to jQuery callback functions. Look at an example below to see a difference.
  • Since URL routes are handled on segment per segment basis; code provides high re-usability, which is unique in current micro frameworks world.
  • URL routes handle only a single path segment
  • URL routes can be crafted without restrictions, giving you an ability to nest them as deep as you want.
  • Caching of table metadata
 

Con

 
  • Documentation is lacking enough information to get you started (I advise you to take a look at the above link Tutorial, Installation, Working Example). It lacks a better organization. Currently, it is not beginner friendly; it took me some time to make it work.
  • New routing model, while excellent, still doesn’t feel that much flexible. This approach still suffers from code bloatedness and code mixing.

 

Example

 
$app->path('posts', function($request) use($app) {
    // Get posts collection
    $app->get(function($request, $postId) use($app) {
        return "GET  /posts";
    });
 
    $app->param('int', function($request, $postId) use($app) {
        // Get single post resource
        $app->get(function($request) use($app, $postId) {
            return "GET  /posts/" . $postId;
        });
 
        // Update single post resource
        $app->post(function($request) use($app, $postId) {
            return "POST  /posts/" . $postId;
        });
    });
});
 

Author Notes

 
This framework is a good starting choice, mainly for smaller projects. New routing model makes it very versatile.
 
On the other hand, because of its age and simplicity, you will need to mix it with other frameworks. Mostly because, unlike some older frameworks (like Fat-free framework), Bullet don’t have additional functionalities (ORM for example).
 
 

2. Fat-Free Framework

 

Links

 
 
Official Site Documentation Installation, Working Example
 
 

Pro

 
  • Lightweight and multifunctional, built like Swiss army knife.
  • Everything is modular.
  • Fast so it should be considered for larger projects.
  • Excellent API and how-to documentation, not the best one but way better than usually expected. Everything is tutorial based, making it easy to follow and implement.
 

Con

 
  • Suffers from code repetition, just like some other similar frameworks.
  • It’s overkill if you are not going to use most of it functionalities
  • ORM module is easy to implement/configure, but there’s a lot of room for improvements. Of course, you can always use another one.

 

Example

 
class WebPage {
    function display() {
        echo 'I cannot object to an object';
    }
}

$f3->route('GET /about','WebPage->display');
 

Author Notes

 
The Fat-free framework is an excellent piece of software. While there’s nothing innovative about it, you will be surprised how much functionality is provided for you. Not to mention it runs smooth and fast. It is half way between micro frameworks and larger frameworks like Zend or Symphony, more so I find it to be an excellent replacement for mentioned more major frameworks, not to mention, it’s heavily modular.
 
It gets a job done.
 
 
Continue Reading
  • Sask is also another micro framework which is really simple to work with. http://saskphp.com

  • hernan

    Nice review.
    BTW, your blog has some strange problem with my browser (Chrome 33, Win) that makes an uncomfortable reading: unless I resize the window width to less than 1024 px, a few letters of the paragraphs text overflows the window on the righ (this should not happen) and still Chrome does not show the horizontal scroll bar.

  • hernan
    • Thanks for your comment you were very proactive and helpful. I will fix this problem as soon as possible.

      Edit: Hm interesting, I’ve recreated this problem, also found another one. Apparently I have a problem with my CSS media queries on certain resolutions.

  • There seems to be some typo (missing ; ) in
    Also, the divs

    show (when inspected on Chrome) at ridicolous large heigth (all the window, it seems).
    Anyway, I’d say that Chrome should be to blame, partially at least. It seems to get confused with the width, it draw outside the window but still believes that everything fits (no horizontal scrollbar, the right arrow key does not work)

  • Ah, the commenting system ate my html…
    Let’s try again escaping…

    typo in: < div class=”blog-article-content rich-content” >

    very tall divs: < div style=”width:100%height: 0.35em;” >

  • Thanks for the review but i think you are discussing about micro frameworks but all of them are not micro at least the Phalcon doesn’t belong to micro level and if you didn’t try Laravel (http://laravel.com) yet then you should check it, one of the bests for now, trnding 🙂

    • Micky Loranger

      Hi Sheikh Heera,

      what are the advantages that laravel offer? It looks great!

      Thks

  • I really thank you for this article, it saved me a lot of time digging to find out witch framework is best for me.

  • Johnny Mnemonic

    And what about Sija framework? http://chermenin.github.io/sija/

  • Thibaud

    Hi, thank you for this post.
    I also like Slim framework and you mentioned a solution in order to handle large routing file, are you talking about http://nesbot.com/2012/11/5/lazy-loading-slim-controllers-using-pimple or another solution ?

  • Kamil Ilyas

    Hello,

    Im very thankful for your post here, it really helped me a lot in choosing my next micro. A quick question though, can u explain a little on the security aspects of phalcon, slim and wave ? and how do they cater them. Also, if you have any other better micro in terms of security, do let me know, thanks in advance 🙂

  • Micky Loranger

    Thank you very much for this article. Can you please make something similar with migrations and oauh2 mini frameworks? Thank in advance

  • I suggest Yee, a rather new Framework…. worth a try. Good documentation and the Developers behind it are very helpful.

  • Hey,

    Did you checked out aura ?

    Here is a quick start http://auraphp.com/manuals/2.0/en/quick-start/ .

    It is purely micro framework! .

    • Thank you for this information, I will check it.

  • Pingback: PHP Slim Micro Framework - Brett's Blog()

  • OnePHP is perfect and pretty simple too.
    http://oneframework.net/

  • Volker

    Yii2 may not be a Micro Framework anymore. But you can put up a Rest service very easy: http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.htm

  • Mike

    Good article. One suggestion, run a spell-check 😉

  • aldo cuevas

    Hello i read all frameworks but which it is best for you

    • Silex then Phalcon. But that’s just my opinion.

  • Don’t forget about Lumen, the micro framework by Laravel: http://lumen.laravel.com/

    • wmac

      I also want to know Dragan’s opinion about it.

      • I like it a lot, unfortunately, I haven’t had time to add it on this list. Give me few days and I will do it.

  • wmac

    I know it is not easy to assign scores, but I really liked what you did in one of your comparisons with scores.

    It would be nice if these comparisons could have them too.

    • Thanks for this suggestion, I will try to devise a fair score system.

  • Robert Anthonie Soriano

    Should I use a micro framework or full stack like laravel with my project? My project is a government website, the dynamic part and those with admin side are the news, events and gallery.

    • If you’re working on a government job, I would advise using a full stack framework. There’s a good chance they’ll require more and more features so smart move would be to go with the best framework you can master. Initially, it will take you more time to set everything up but you’ll make it up on a long run.

      • Robert Anthonie Soriano

        Yes thanks. I’m using laravel

  • shruti aggarwal

    I am new to php and have to choose a rest api framework for a mobile apps where there is max 30-40 rest apis. which rest api framework will be best for me ? Any suggestions

    • It depends on a number of calls per second. My advice, go with Phalcon if you need raw speed.

      • Eduardo Moura

        Slim

    • Eduardo Moura

      First we make a restful api with the necessary routes, offering json resources, listing something (GET), registration something (POST).

      Then do the consumers of these resources json. may be on Android, iOS, WinMobile, and even (HTML5 JS CSS3)

    • Eduardo Moura

      And if you are working with HTML views but on a project (consumer) PHP, to consume the routes of API in json, we need the cURL library.

  • GT

    First of all, thanks to the author for this very nice article. I have 14 year php experience, but until now, I had to use more robust frameworks, build my own, or use one that others build privately. Now I’m looking for framework to create backend for a frontend which will based on angular or polymer.

    After inspecting all of these frameworks, I’m hesitating between phalcon and lumen.

    Phalcon looks extremely flexible! MVC functionality is optional for example. It’s data handling seems really well thought up, mature and feature rich. This is the real strength of it. You can even use only for that. There are also quite lot amount of 3rd party resources available (the blog author didn’t mention this important factor besides 3rd party support). While it’s not a requirement for me, but the bootstrap support is big plus for me (It’s well known for me). The php-extension nature makes it more unique, gives speed, but since I can’t debug it via xdebug, can cause problems for me. In many cases, debugging helps understand the code even faster than any amount or quality or documentation. Has great documentation. I don’t care about lower 3rd party support now.

    While I like Lumen’s ability to convert into a robust, very feature rich framework. It’s structure and usage shows similarity to some other framework like Slim, I see as de facto standard at these type of frameworks. It looks very mature and has great documentation.

  • David Berlioz

    Hi, very good stuff !
    What do u thiink about Restler ?
    http://www.luracast.com/products/restler

    • Never heard of it, give me some time and I’ll take a look.

  • Another inaccurate article taking a gaunt at Lumen’s speed. It’s been confirmed that Lumen is the most performant micro-Framework to date.

    • And tham my friend is called a weasel statement, google it.

      1. Who has confirmed that?
      2. On top of what data?
      3. Most performant PHP micro-Framework? What about Java and .NET?

      I hope you get a gist.

      • “The benchmarks themselves are actually really simple. I use a Homestead VM since that is something anyone can recreate. In my tests, I allocated 2GB of RAM to the machine. Of course, benchmark numbers are going to vary depending on the hardware of your host machine. I personally am running benchmarks on a 2012 Macbook Pro Retina 15″ with 16GB of RAM. So, don’t be surprised if your numbers are different than my numbers.” ~ Taylor Otwell (Creator of Lumen)

  • Eric

    Wrong, Lumen is the fastest of all micro framework and besides 3 Slim has been updated in the butts to improve the speed knowing that Lumen has basic library of more than Slim. Lumen is top notch for a small application instance with most unlike Slim or otherwise. You could even add a category limit “very little micro framework ” for the framework as bullet or slim.
    Thank you for this article

    • Mark

      It depends how you define fast but Lumen certainly isn’t the fastest, Phalcon is by far the fastest in terms of response times and request per second because its Libary is written in C, no pure PHP implementation will ever be able to compete with that

      • Eric

        Sure, but there we are not comparing the same things. Besides Zend Framework should have taken a direction as to Phalcon , allow users the option of using a php framework in compiled dll taking example of Phalcon but Phalcon not a very practical framework on long- term projects , professionally and in a team.

        • Davey McNight

          How is not practical for long term projects and teams? It is really easy to extend and if you have Phalcon Devtools it is to generate your classes.

          • Trent Ramseyer

            He thinks it is not practical because he likes Lumen, he somehow has turned a blind eye to anything that is actually faster than Lumen, Phalcon Full Framework is faster than Lumen. Codeigniter 3 is faster than Lumen, Phpixie is faster than Lumen. There should be a category for bloated frameworks so Laravel can shine in that category.

  • hemant menaria

    In my openion right now Laravel is the first choice of developers.

  • Brick Heck

    We don’t trust components such as Composer, on our server, so many of these frameworks will not do.

    • Trent Ramseyer

      Most of PHP development world is moving to packages and Composer install… so not sure why you wouldn’t trust a Composer package vs an all inclusive framework. You will have to vet them equally for malware.

  • FireFalcon

    Our team is planning to develop a large REST API that will deal with large amount of data and speed is a primary issue in here.
    Which framework do you suggest? Can we go with micro-frameworks?