So it has taken me some time to think about the next part of this series and how deep I really want to dive into each framework. For this article and the rest I end up making in the series I will do more of a first impression, rather than a deep dive. This should mimic more of a prototyping session than full feature review. Ultimately using a framework (or not) is matter of preference and my role with these articles should be to note the following points:
- Are the docs clear and easy to follow
- How versatile is the framework
- A quick glance at performance
With that out of the way lets take a look at Lumen. Lumen is a micro-framework based off Laravel which by extension is partially based on Symfony components. In my quick impression of Lumen I would say usage is relatively straight forward, especially after using AdonisJS, which is modeled after Laravel.
Documentation
The docs is the first part that struck me as a bit odd and hard to follow regarding Lumen. The docs have a bad habit of basically saying "it's not documented here, go look at the Laravel docs." This could be fine, but some of the context and usage is different in Lumen than in Laravel so sometimes you have to piece it together yourself. This was immediately apparent when I simply just wanted to do a raw sql query. The docs say
$results = app('db')->select("SELECT * FROM users");
but it was unclear to me that 'app' is a global function.
Versatility
Due to the way Lumen is structured you have mostly free reign over what you want to do. Besides a few things you can mostly use raw PHP based off everything I have seen. Creating services is fairly straightforward and you can rely on the dependency injection engine to managed dependencies for you. I did not toy around with ORMs since this is a micro-framework, but there is the option to use them if you want. It looks like Eloquent, the Laravel ORM, is readily available if you want. Overall I don't think there is much you couldn't due with Lumen as long as it is supported by the PHP platform.
Setting up a route was fairly trivial. You can define the route in web.php with a callback or a string reference to a class function.
$router->get('league_players/raw/{id}', function($id) {
$sql = "
select * from
league_player lp
join league l on lp.league_id = l.id
join player p on lp.player_id = p.id
where lp.id = :id
";
return app('db')->select($sql, ['id' => $id]);
});
$router->get('league_players/service/{id}', 'LeaguePlayerController@getLeaguePlayer');
Dependency Injection
Lumen does have dependency injection available and I was able to create a route using a class controller and injecting a service to the class route. I did not notice a significant overhead using the class method and DI.
Performance
So I am going to change up my performance testing from now on. Since I do not have a separate machine to run testing on I will just give my two cents and a repo you can use to do your own testing.
Running through a few scenarios I found Lumen to be close to but faster then Symfony 4. Under single requests there was no difference. At a 100+ concurrent requests you do notice Lumen pulling ahead.
Final Thoughts
Overall I am not super impressed with Lumen. In today's world where expressjs is commonplace I feel like the need for Lumen is not really there. The docs are adequate but not superb and performance (stock at least) is not good enough vs Symfony to really consider using it over Symfony.
I would say you are better off using a full featured PHP framework, or picking up express (and learning node.js) if you want a straightforward microframework with high performance. Another option would be to create your own with some simple setup if you really want to stick to php.
Well that about wraps up my impressions of Lumen. Let me know your thoughts in the comments.
What framework/microframework should I look at next? I'm thinking something in js/go, let me know!
EDIT:
I forgot to link the repo so you can play around with what I did! https://github.com/buphmin/LumenComparison
Top comments (4)
What about Slim 3 ? I like it because of its simplicity and performance.
I would like to here about it from you
I will take a look at the very least!
Ok
Yeah I definitely felt like it was missing something even for a microframework.