How does Laravel 5.2 API compare to Lumen? [duplicate] - php

This question already has answers here:
Differences and Similarities Between Lumen and Laravel
(8 answers)
Closed 6 years ago.
I'm going to make an API that will have many requests (around 5000 each minute minimum, but could possibly be a lot more). I'm wondering what framework is better for that: Laravel 5.2 or Lumen?
Lumen is a micro framework and especially made for API's but since Laravel 5.2 it's possible to change the middleware. So for my api I could only bind the middleware I need, so no authentication and so on.
That's a big difference with earlier versions of Laravel where the full framework was loaded. So is it since 5.2 still recommended to use Lumen or are the differences in performance very, very small?

There are some benchmarks out there for PHP frameworks. It's really hard to perform and read benchmarks in a good way, but they should still be able to hint about the difference between them. This seems like a good source: https://github.com/kenjis/php-framework-benchmark. That puts Lumen at 412.36 requests per second, and Laravel at 91.59 requests per second. If your API will have a lot of requests you should probably go with Lumen (or some even faster framework).
If you can you should also use PHP7 since the performance gains are huge compared to PHP5. You can decrease memory load an response times significantly, take a look at this benchmark for Symfony for example.
Disabling middleware for increasing performance is not a problem. There are different ways to register middleware in Laravel. Removing all middleware that comes by default in both the HTTP kernel and on routes is a small task. However there are a lot more to performance than the middleware. Laravel will bootstrap many components that you do not need, this is the reason why Lumen was created in the first place. I do not have a benchmark on how the middleware affects performance specifically, but I would assume it's not the main performance degrader.

The performance with Lumen will be way faster. Unless you are required to do some really complex operations that only Laravel / Laravel packages will handle, then just go with Lumen.
Also, if you're not going to make use of many features of Lumen or Laravel to a particular endpoint that's going to receive a lot of requests, just point that route to another PHP file in Nginx as there's no point in loading all of Laravel or Lumen's components if there is no need.
Good luck!

Related

Laravel is great but... where's the consideration for HATEOAS?

I've begun using Laravel 5.4 instead of Spring boot for a web application I'm currently developing and it's going great. I'm really enjoying the lack of verbose boilerplate that Java/Spring has. However, one of my requirements is that the API must be HATEOAS.
I've literally searched for days for research material and only come up with a couple of not-so-popular libraries. Is there a reason for this complete lack of exposure of HATEOAS for Laravel when for other web application frameworks there's at least some material?
Edit: I'm not trying to talk down on Laravel, I just want to know why there's no resource on HATEOAS implementations with Laravel as the framework, or if I've missed it, where I can read up on some HATEOAS Laravel goodness.
Since Laravel uses the Symfony underneath, I think this repo would work: https://github.com/willdurand/Hateoas

Difference between laravel 5 and codeigniter 3

This may silly question. But I am going to start new project. I am quite confused which framework is best out of Codegniter 3 and Laravel 5.
What is the main difference between them.
Thanks in Advance
Right now, I personally prefer Laravel since it supports PHP7 unlike CodeIgniter (I still haven't read if CodeIgniter 3 supports PHP7). And based on personal experience, Laravel (through Eloquent) has "beautifully-written-codes".
Here are some references for you to check out: (I made sure to post both sides to not be bias)
https://www.codeclouds.com/blog/laravel-vs-codeigniter-a-difficult-choice/
https://www.clickittech.com/developer/laravel-vs-codeigniter-which-one-is-the-best-to-use
http://www.codeigniterhands.com/codeigniter-or-laravel
http://laravel.io/forum/07-08-2014-laravel-vs-codeigniter-a-difficult-choice
https://therightsw.com/codeigniter-vs-laravel-vs-yii-vs-cakephp/ (with grades for usability)
Each framework have their own features and capabilities, used during the development of application. Laravel is one of the highly used, open-source modern web application framework that designs customized web applications quickly and easily.Laravel is used not only for big project but also best to use for small project.
Best framework in 2018
If you want a framework with exceptional performance, with nearly no configuration, not using cmd and not interested with large scale libraries and also your project is in small scale it's better to use codeIgniter.
CodeIgniter3 vs Laravel5
Both framework are good in there place.
Laravel made from multiple open source project which make laravel more efficient , reliable and secure.
Where, laravel used blade engine.
It used composer for package manager.
It provide unit testing.
It provide more security.
It provide beautiful redis queue front portal called laravel horizon.
Disadvantage : laravel used predis which is slower, because it is written in php.where phpredis is more faster, but laravel 5.* Don't support it.
I will recommend you to use Laravel beacuse of:
Built in authentication
Awesome migrations
Artisan commands to do anything in your project
Built in pagination (It's took long in Codeigniter)
Eloquent (Very easy way to interact with your database)
Relationships
Routes
Easy API building
Easy debugging
Huge number of packages and libraries etc.

Caching most of Symfony components and services

Having a Java background, one point I have missed during many years is that PHP recreates everything at every request.
So using the Symfony framework, we recreate every components of this - yet great - framework. Every service, all the router, are built and rebuilt.
We can cache data in $_SESSION, but we save 50 times data if we have 50 users. I thought I could use static or $_SERVER, but it doesn't work the Java way.
The PHP way is to use Memcached and there are plenty of exemples caching the doctrine requests, but I haven't seen any of them caching the Router or the Services. Do you know exemples, or is it just a bad idea ?
That's one of the characteristics of PHP, nothing lives once the request is finished.
There're a couple of projects where they wrap the bootstrapping process of symfony so it's only run once. Here's the project: php-pm and an article describing it's usage

What's the recommended location to get and set the Cache code ? Laravel 5.2

What I am doing ?
Below is the code to get and set the data in cache
\Cache::put('Categories', $Categories, 60);
\Cache::forget('Categories');
Question
What's the recommended location to get and set the Cache code ? So far I did this in the Controller file.
Take a look at Laravel 5.1 Cache especially Cache Usage part, where you set or get cache depending to you and workflow of your app.
I recommended to use them inside controllers.
Like with most of the questions of Where Do I Put X the answer is it depends. There is absolutely nothing wrong with doing it in your controller if your doing a small application and maybe only caching a few things.
If your writting a really big application or something quite complexted then you could consider doing your caching via a repository see Using Repository Pattern in Laravel 5 for some information about the Repository Pattern. If you wanted you could make use of Laravel 5 Repositories this provides not only a clean and well documented way to implement repositories but also it has specific way of doing caching see Cache Usage.

Laravel 4 how to lazy load controllers?

Recently I've discovered that Laravel 4 is including all the controllers on each request regardless if it needs it or not, even though Composer has the whole controller architecture mapped in its autoload. I'm trying to build a high traffic website and I'm trying to minimize the overhead as much as possible before starting to make any hardware scaling. Do you have any idea how can I "force" laravel 4 into lazy loading the classes, as in ... whenever they are requested by the code for the given request.
The way I see it now, when it parses the routes it includes all controllers, makes a reflection class of all of them to parse the methods so that it has them mapped in the request memory. IMO that's quite the overkill. A simple Hello World costs me 5Mb ram and 15ms page generation time. That is too much for me. It's like the most hyped framework at the moment and its hyped as lightweight but 5mb/15ms is not lightweight in any case :/
There is a great argument/explanation here: http://forums.laravel.io/viewtopic.php?id=8175
Laravel 4 is meant to use more framework agnostic packages than Laravel 3.
Laravel 3 is very lightweight, perhaps you could look into using v3 instead. It's still actively being used and supported throughout the community.

Categories