前几天 Taylor Otwell 就在 Twitter 上透露了 Lumen 框架的消息并附上了一张网站截图,但是没有具体细节,也就是过了三四天的样子,谜底揭晓了 -- Lumen 来了,一个类似 Slim 的微框架(micro-framework)。

下面是 Laravel-News 对 Taylor Otwell 的采访,直接粘过来白天再翻译吧,有兴趣的同学自己看看英文或者按照 Lumen 中文文档先动手试一试吧,既然说了 Lumen 是基于 Laravel 构建的,自然相通的地方不少,对熟悉 Laravel 的同学来说不难。

Lumen 中文文档地址(翻译中):http://lumen.golaravel.com/docs/

顺便打个广告(有效期3天):某BAT大厂招 Lumen 超级工程师N名,年薪百万,要求具有 3 天以上 Lumen 开发经验,用 Lumen 开发过企业级应用的优先!简历请发到以下邮箱: lumen@golaravel.com


Lumen 来了

Lumen 是一个全新的、由 Taylor Otwell 设计的 PHP 框架,主要面向构建快速的微服务(micro-services)和 API 系统。如果你要的就是速度,那么 Lumen 可能是一个最佳选择。

One of the neat things about the framework is you can still use all the Laravel features you love like Eloquent, caching, queues, validation, routing, middleware, and the powerful Laravel service container. Plus if you start your project with Lumen and eventually need even more power, moving to the full featured Laravel is a simple process.

To find out more behind the scenes I had a quick interview with Taylor about the project:

是什么原因促使你创造了 Lumen?

当我构建 Envoyer 时,曾经写了两个小型的 “micro-services” 为其提供辅助支持。其中一个是用来做部署之后的健康检查的。这是个很小的应用程序,并且被部署在三个不同的 DigitalOcean 域上。最开始我是用 Silex 开发这个应用程序的;可是,后来我就必须要花时间重新研究如何创建 PDO 数据库连接了。我更希望有一个简化的 Laravel,并且内建的数据库可以支持 DB::update

另一个 Envoyer 服务是 “heartbeat” 定时任务监控。由于这些 URL 需要在每分钟被检查数百次,. Since these URLs could be called every minute by hundreds, if not thousands of Cron jobs, I needed that to be very fast. So, I used Slim for that service. 但是,后来,我必须要设置更多的健壮性方面的错误处理和数据库连接了。这是我再次希望能够有一个轻量级的 Laravel。

这就是 Lumen 诞生的起因。构造这个框架并找到让它足够快的解决方案至少花费了三四次重构的时间。在我能够让 Lumen 比 Silex 和 Slim 都更快之后才将其发布了。我不希望发布一个比相同方案还要慢的东西出来。

Lumen 这个名字有何缘由?

Lumen is a play on the “Illuminate” components that Laravel utilizes. The Illuminate components are the individual pieces of the Laravel framework such as database, cache, queue, etc. So, first, I think Lumen sounds cool as a name. It’s only two syllables, instead of three like Laravel. That may sound crazy, but I think about that kind of thing and the mental images that are conjured up when you say the word. Of course, it also continues the tradition of “light” based names.

Being able to upgrade right into Laravel is huge. Was this the plan from the beginning?

Yes, and it’s really just a natural outcome of using the Illuminate components that make up the full-stack Laravel framework. Since we use those components, it’s easy to provide a really great upgrade story, and I feel like that is something missing from other micro-framework solutions. Since the Laravel eco-system now contains both a full-stack framework and a micro-framework that are “officially” supported, we can provide really great upgrade stories.

How were you able to get the framework so fast, while still keeping so many great features?

This is again due to the great convenience of the Illuminate components. Basically, all I needed to do was “glue” them together in a different way than a full-stack framework would glue them together. This means instead of maximum flexibility in the bootstrapping process, Lumen opts for maximum speed. The actual Lumen framework repository is probably only a dozen files or so. The rest is made up of the Illuminate components. This allowed me to flesh out the features of the framework very quickly, though it did take me three or four iterations to find a solution that was really, really fast while still providing very powerful features.


Lumen is surely to a big hit and I think the way you can easily move into Laravel is a huge long term benefit for not only Lumen but the whole Laravel ecosystem. To stay up to date with all the latest happenings on Lumen be sure and join the weekly newsletter.