pushrbx/lumen-roadrunner
Composer 安装命令:
composer require pushrbx/lumen-roadrunner
包简介
Lumen framework on RoadRunner
关键字:
README 文档
README
Easy way for connecting RoadRunner and Lumen applications. This is a fork of spiral/roadrunner-laravel, which makes it work with lumen instead of the full laravel framework.
Please note that this lib is not production ready yet, it's under development.
Installation
Make sure that RR binary file already installed on your system (or docker image). Require this package with composer using next command:
$ composer require pushrbx/lumen-roadrunner
Installed
composeris required (how to install composer).
After that you can "publish" package configuration file (./config/roadrunner.php) using next command:
$ php ./artisan vendor:publish --provider='pushrbx\LumenRoadRunner\ServiceProvider' --tag=config
Important: despite the fact that worker allows you to refresh application instance on each HTTP request (if worker started with option --refresh-app, eg.: php ./vendor/bin/rr-worker start --refresh-app), we strongly recommend avoiding this for performance reasons. Large applications can be hard to integrate with RoadRunner (you must decide which of service providers must be reloaded on each request, avoid "static optimization" in some cases), but it's worth it.
Usage
After package installation you can use provided "binary" file as RoadRunner worker: ./vendor/bin/rr-worker. This worker allows you to interact with incoming requests and outgoing responses using laravel events system. Event contains:
| Event classname | Application object | HTTP server request | HTTP request | HTTP response | Exception |
|---|---|---|---|---|---|
BeforeLoopStartedEvent |
✔ | ||||
BeforeLoopIterationEvent |
✔ | ✔ | |||
BeforeRequestHandlingEvent |
✔ | ✔ | |||
AfterRequestHandlingEvent |
✔ | ✔ | ✔ | ||
AfterLoopIterationEvent |
✔ | ✔ | ✔ | ||
AfterLoopStoppedEvent |
✔ | ||||
LoopErrorOccurredEvent |
✔ | ✔ | ✔ |
Simple .rr.yaml config example (full example can be found here):
For
windowspath must be full (eg.:php vendor/pushrbx/lumen-roadrunner/bin/rr-worker start)
version: "2.7" server: command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-relay.sock" relay: "unix:///var/run/rr-relay.sock" http: address: 0.0.0.0:8080 middleware: ["static", "headers", "gzip"] pool: max_jobs: 64 # feel free to change this supervisor: exec_ttl: 60s headers: response: X-Powered-By: "RoadRunner" static: dir: "public" forbid: [".php"]
Socket or TCP port relay usage is strongly recommended for avoiding problems with dd(), dump(), echo() and other similar functions, that sends data to the IO pipes.
Roadrunner server starting:
$ rr serve -c ./.rr.yaml
Listeners
This package provides event listeners for resetting application state without full application reload (like cookies, HTTP request, application instance, service-providers and other). Some of them already declared in configuration file, but you can declare own without any limitations.
Helpers
This package provides the following helpers:
| Name | Description |
|---|---|
\rr\dump(...) |
Dump passed values (dumped result will be available in the HTTP response) |
\rr\dd(...) |
Dump passed values and stop the execution |
\rr\worker() |
Easy access to the RoadRunner PSR worker instance |
Known issues
Performance degradation
...when file driver is set for your sessions. Please, use redis (or something similar) driver instead (related issue). This package or/and RoadRunner has nothing to do with it, but since this is a fairly common issue - it is described here.
Controller constructors
You should avoid to use HTTP controller constructors (created or resolved instances in a constructor can be shared between different requests). Use dependencies resolving in a controller methods instead.
Bad:
<?php use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Controllers\Controller; class UserController extends Controller { /** * The user repository instance. */ protected $users; /** * @var Request */ protected $request; /** * @param UserRepository $users * @param Request $request */ public function __construct(UserRepository $users, Request $request) { $this->users = $users; $this->request = $request; } /** * @return Response */ public function store(): Response { $user = $this->users->getById($this->request->id); // ... } }
Good:
<?php use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Controllers\Controller; class UserController extends Controller { /** * @param Request $request * @param UserRepository $users * * @return Response */ public function store(Request $request, UserRepository $users): Response { $user = $users->getById($request->id); // ... } }
Middleware constructors
You should never to use middleware constructor for session, session.store, auth or auth Guard instances resolving and storing in properties (for example). Use method-injection or access them through Request instance.
Bad:
<?php use Illuminate\Http\Request; use Illuminate\Session\Store; class Middleware { /** * @var Store */ protected $session; /** * @param Store $session */ public function __construct(Store $session) { $this->session = $session; } /** * Handle an incoming request. * * @param Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $name = $this->session->getName(); // ... return $next($request); } }
Good:
<?php use Illuminate\Http\Request; class Middleware { /** * Handle an incoming request. * * @param Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $name = $request->session()->getName(); // $name = resolve('session')->getName(); // ... return $next($request); } }
Testing
For package testing we use phpunit framework and docker-ce + docker-compose as develop environment. So, just write into your terminal after repository cloning:
$ make build $ make latest # or 'make lowest' $ make test
Changes log
If you find any package errors, please, make an issue in a current repository.
License
MIT License (MIT). Please see LICENSE for more information. Maintained by pushrbx.
pushrbx/lumen-roadrunner 适用场景与选型建议
pushrbx/lumen-roadrunner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Bridge」 「laravel」 「lumen」 「roadrunner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pushrbx/lumen-roadrunner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pushrbx/lumen-roadrunner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pushrbx/lumen-roadrunner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Soluble PHP Java bridge integration
Testing Suite For Lumen like Laravel does.
Bridge between JMS Serializer Bundle and Superdesk Web Publisher.
Builds a Bridge between Zend Expressive and Plugin Managers of Zend\MVC
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Class to generate a standard structure for api json responses
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-12