php Lumen 和 Laravel 的异同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29647960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Differences and Similarities Between Lumen and Laravel
提问by Ranjeet Karki
I read the documentation and it seems Lumen is Laravel with less features. I must be missing something. I am looking for a comparison table of the components and features of both Laravel and Lumen. Does anyone know the differences?
我阅读了文档,似乎 Lumen 是 Laravel,但功能较少。我肯定错过了什么。我正在寻找 Laravel 和 Lumen 的组件和功能的比较表。有谁知道区别?
回答by lukasgeiter
Update (5.2)
更新 (5.2)
With the latest version of Lumen (5.2) the Microframework focuses on Stateless APIs.
The documentationstates:
在最新版本的 Lumen (5.2) 中,微框架专注于无状态 API。
该文件指出:
Lumen 5.2 represents a shift on slimming Lumen to focus solely on serving stateless, JSON APIs. As such, sessions and views are no longer included with the framework.If you need access to these features, you should use the full Laravel framework.
Lumen 5.2 代表了精简 Lumen 的转变,专注于提供无状态的 JSON API。因此,框架中不再包含会话和视图。如果您需要访问这些功能,您应该使用完整的 Laravel 框架。
Original answer (<= 5.1)
原始答案 (<= 5.1)
Lumen is all about speed. It's faster and can handle more requests per second than Laravel.
流明是关于速度的。它比 Laravel 更快,每秒可以处理更多的请求。
Laravel is a framework that glues together a lot of components (3rd party and Laravels own components). Now Lumen makes use of a lot of the same components, but strips down the bootstrapping process to a minimum. You could say it is a "different glue", the components (and therefore a lot of the features) are mostly the same.
Laravel 是一个将许多组件(3rd 方和 Laravel 自己的组件)粘合在一起的框架。现在 Lumen 使用了许多相同的组件,但将引导过程减少到最低限度。您可以说它是“不同的胶水”,组件(以及因此的许多功能)大致相同。
The performance improvement is achieved by taking away some of the flexibility of the framework in terms of configuration and altering the default boot process.
性能提升是通过在配置和更改默认启动过程方面取消框架的一些灵活性来实现的。
Besides that, more features are disabled by default and have to be activated before they can be used. As an example: Facades(like DB::table()
)
You first need to uncomment this line in bootstrap/app.php
to enable them:
除此之外,默认情况下禁用了更多功能,必须先激活它们才能使用。例如:Facades(like DB::table()
)
您首先需要取消注释此行bootstrap/app.php
以启用它们:
// $app->withFacades();
The same goes for Dotenv environment files and Eloquent.
Dotenv 环境文件和 Eloquent 也是如此。
For routing Lumen uses nikic/FastRouteinstead of symfonys router because it performs a lot better and gives the micro-framework another big boost.
对于路由,Lumen 使用nikic/FastRoute而不是 symfonys 路由器,因为它的性能要好得多,并为微框架提供了另一个巨大的推动。
Other than that pretty much everything is the same as in Laravel.
除此之外,几乎所有内容都与 Laravel 中的相同。
Good reads on Lumen
Lumen 上的好书
- Documentation(especially the introduction)
- Article from Matt Stauffer
- Interview with Taylor Otwell(especially the last question)
- Reddit discussion
- Laracast: Introducing Lumen
- 文档(尤其是介绍)
- 马特·斯托弗的文章
- 专访Taylor Otwell(尤其是最后一个问题)
- Reddit 讨论
- Laracast:介绍 Lumen
回答by d4nyll
Lumen is not designed to replace Laravel, rather, it is a more specialized (and stripped-down) framework designed for micro-services and APIs. It took away unneeded features for an API such as HTTP sessions and cookies, and also limited the number of configuration options. Out-of-the-box, Lumen sacrified the flexibility of Laravel for speed.
Lumen 并非旨在取代 Laravel,而是为微服务和 API 设计的更专业(和精简)的框架。它去除了 API 不需要的功能,例如 HTTP 会话和 cookie,还限制了配置选项的数量。开箱即用,Lumen 为了速度牺牲了 Laravel 的灵活性。
However, you can add Laravel components to Lumen to extend it, so it canbe used for more than just micro-services and API. However, if your goal is to extend Lumen to become a website, you might as well use Laravel instead.
但是,您可以将 Laravel 组件添加到 Lumen 以对其进行扩展,因此它不仅可以用于微服务和 API。然而,如果你的目标是将 Lumen 扩展成一个网站,你不妨改用 Laravel。
They also have different use cases. Lumen and Laravel are meant to work together. For APIs and services are frequently get called, use Lumen. For user-facing applications, use Laravel.
它们也有不同的用例。Lumen 和 Laravel 旨在协同工作。对于经常被调用的 API 和服务,请使用 Lumen。对于面向用户的应用程序,请使用 Laravel。
This answer is taken from a blog postI wrote that explains the difference between Lumen and Laravel.
这个答案取自我写的一篇博客文章,它解释了 Lumen 和 Laravel 之间的区别。
回答by Ivan Dokov
Quote from Matt Stauffer
马特·斯托弗的报价
Lumen has the same foundation as Laravel, and many of the same components. But Lumen is built for microservices, not so much for user-facing applications (although it can be used for anything.) As such, frontend niceties like Bootstrap and Elixir and the authentication bootstrap and sessions don't come enabled out of the box, and there's less flexibility for extending and changing the bootstrap files.
Lumen 与 Laravel 具有相同的基础,以及许多相同的组件。但是 Lumen 是为微服务而构建的,而不是面向用户的应用程序(尽管它可以用于任何事情。)因此,像 Bootstrap 和 Elixir 这样的前端细节以及身份验证引导程序和会话并不是开箱即用的,并且扩展和更改引导文件的灵活性较低。
You can read more here
你可以在这里阅读更多
回答by pardeep
Lumen microframework is a lightweight version of Laravel full-stack framework. Lumen use the Laravel syntax and components, and can be 'upgrade' easily to Laravel.
Lumen 微框架是 Laravel 全栈框架的轻量级版本。Lumen 使用 Laravel 语法和组件,可以轻松“升级”到 Laravel。
Lumen is a more specialized (and stripped-down) framework designed for Microservices development and API development. So, some of the features in Laravel such as HTTP sessions, cookies, and templating are not needed and Lumen takes them away, keeping what's essential - routing, logging, caching, queues, validation, error handling and a couple of others.
Lumen 是一个更专业(和精简)的框架,专为微服务开发和 API 开发而设计。因此,Laravel 中的某些功能(例如 HTTP 会话、cookie 和模板)不是必需的,Lumen 将它们拿走,保留了必不可少的功能 - 路由、日志记录、缓存、队列、验证、错误处理和其他一些功能。
回答by Shobi
Why Lumen ?
为什么是流明?
Lumen is the perfect solution for building Laravel based micro-services and blazing fast APIs. In fact, it's one of the fastest micro-frameworks available. It has never been easier to write stunningly fast services to support your Laravel applications. Doc
Lumen 是构建基于 Laravel 的微服务和极速 API 的完美解决方案。事实上,它是可用的最快的微框架之一。编写极快的服务来支持 Laravel 应用程序从未如此简单。文件
Lumen is a framework to build APIs, which will essentially serve JSON responses for your requests. That's it.
Lumen 是一个构建 API 的框架,它本质上将为您的请求提供 JSON 响应。就是这样。
These kinds of applications are known as web services in general.
这些类型的应用程序通常称为 Web 服务。
As of Lumen 5.2 update, it doesn't support laravel views, sessions etc... for that you will have to upgrade to full laravel framework.
从 Lumen 5.2 更新开始,它不支持 Laravel 视图、会话等……因此您必须升级到完整的 Laravel 框架。
Some components of the Laravel framework is swapped with other packages in favour of performance. check them here
Laravel 框架的某些组件与其他包交换以提高性能。在这里检查它们
Example scenarios where we can consider Lumen
我们可以考虑 Lumen 的示例场景
- You might want to open up some features of an application to other developers via API
- Your application needs to support both web and mobile application, then it will be perfect to store the data in a DB wrapped in Lumen API.
- When you consider scalability as an important point, you may need lumen
- 您可能希望通过 API 向其他开发人员开放应用程序的某些功能
- 您的应用程序需要同时支持 Web 和移动应用程序,那么将数据存储在一个包裹在 Lumen API 中的数据库中将是完美的。
- 当您将可扩展性视为重点时,您可能需要流明
回答by vaibhavmht225
The main difference between laravel and lumen is, Laravel can have artisan commands, which lumen doesn't have.
Laravel 和 lumen 的主要区别在于,Laravel 可以有工匠命令,而 lumen 没有。