spiral/roadrunner-http
Composer 安装命令:
composer require spiral/roadrunner-http
包简介
RoadRunner: HTTP and PSR-7 worker
README 文档
README
RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a service with the ability to extend its functionality on a per-project basis.
RoadRunner includes PSR-7/PSR-17 compatible HTTP and HTTP/2 server and can be used to replace classic Nginx+FPM setup with much greater performance and flexibility.
Official Website | Documentation
Repository:
This repository contains the codebase PSR-7 PHP workers. Check spiral/roadrunner to get application server.
Requirements:
Ensure that your server is configured with the following PHP versions and extensions:
- PHP >=8.1
- ext-protobuf: This extension is optional but highly recommended for installation. Without it, performance may be up to 50% lower.
- RoadRunner ^2023.3
Installation:
To install application server and HTTP codebase:
composer require spiral/roadrunner-http nyholm/psr7
You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:
composer require spiral/roadrunner-cli --dev
To download latest version of application server:
vendor/bin/rr get
You can use any PSR-17 compatible implementation.
Example:
To init abstract RoadRunner worker:
<?php require __DIR__ . '/vendor/autoload.php'; use Nyholm\Psr7\Response; use Nyholm\Psr7\Factory\Psr17Factory; use Spiral\RoadRunner\Worker; use Spiral\RoadRunner\Http\PSR7Worker; // Create new RoadRunner worker from global environment $worker = Worker::create(); // Create common PSR-17 HTTP factory $factory = new Psr17Factory(); // // Create PSR-7 worker and pass: // - RoadRunner worker // - PSR-17 ServerRequestFactory // - PSR-17 StreamFactory // - PSR-17 UploadFilesFactory // $psr7 = new PSR7Worker($worker, $factory, $factory, $factory); while (true) { try { $request = $psr7->waitRequest(); } catch (\Throwable $e) { // Although the PSR-17 specification clearly states that there can be // no exceptions when creating a request, however, some implementations // may violate this rule. Therefore, it is recommended to process the // incoming request for errors. // // Send "Bad Request" response. $psr7->respond(new Response(400)); continue; } try { // Here is where the call to your application code will be located. // For example: // // $response = $app->send($request); // // Reply by the 200 OK response $psr7->respond(new Response(200, [], 'Hello RoadRunner!')); } catch (\Throwable $e) { // In case of any exceptions in the application code, you should handle // them and inform the client about the presence of a server error. // // Reply by the 500 Internal Server Error response $psr7->respond(new Response(500, [], 'Something Went Wrong!')); // Additionally, we can inform the RoadRunner that the processing // of the request failed. $worker->error((string)$e); } }
Stream response
To send a response in a stream, set the $chunkSize property in PSR7Worker:
$psr7 = new PSR7Worker($worker, $factory, $factory, $factory); $psr7->chunkSize = 512 * 1024; // 512KB
Now PSR7Worker will cut the response into chunks of 512KB and send them to the stream.
Early hints
To send multiple responses you may use the \Spiral\RoadRunner\Http\HttpWorker::respond() method with
the endOfStream parameter set to false. This will send the response to the client and allow you to send
additional responses.
/** @var \Spiral\RoadRunner\Http\PSR7Worker $psr7 */ $httpWorker = $psr7->getHttpWorker() ->respond(103, header: ['Link' => ['</style.css>; rel=preload; as=style']], endOfStream: false); // End of stream will be sent automatically after PSR7Worker::respond() call $psr7->respond(new Response(200, [], 'Hello RoadRunner!'));
Testing:
This codebase is automatically tested via host repository - spiral/roadrunner.
License:
The MIT License (MIT). Please see LICENSE for more information. Maintained
by Spiral Scout.
spiral/roadrunner-http 适用场景与选型建议
spiral/roadrunner-http 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.44M 次下载、GitHub Stars 达 80, 最近一次更新时间为 2020 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 spiral/roadrunner-http 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spiral/roadrunner-http 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.44M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 81
- 点击次数: 13
- 依赖项目数: 60
- 推荐数: 6
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-16
