spiral/roadrunner-bridge
Composer 安装命令:
composer require spiral/roadrunner-bridge
包简介
RoadRunner integration package
README 文档
README
Requirements
Make sure that your server is configured with following PHP version and extensions:
- PHP 8.1+
- Spiral Framework 3.14+
- Extension
protobuf(recommended)
Installation
To install the package:
composer require spiral/roadrunner-bridge
After package install you need to add bootloaders from the package in your application on the top of the list.
use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge; protected const LOAD = [ RoadRunnerBridge\HttpBootloader::class, // Optional, if it needs to work with http plugin RoadRunnerBridge\QueueBootloader::class, // Optional, if it needs to work with jobs plugin RoadRunnerBridge\CacheBootloader::class, // Optional, if it needs to work with KV plugin RoadRunnerBridge\GRPCBootloader::class, // Optional, if it needs to work with GRPC plugin RoadRunnerBridge\CentrifugoBootloader::class, // Optional, if it needs to work with centrifugo server RoadRunnerBridge\TcpBootloader::class, // Optional, if it needs to work with TCP plugin RoadRunnerBridge\MetricsBootloader::class, // Optional, if it needs to work with metrics plugin RoadRunnerBridge\LoggerBootloader::class, // Optional, if it needs to work with app-logger plugin RoadRunnerBridge\LockBootloader::class, // Optional, if it needs to work with lock plugin RoadRunnerBridge\ScaffolderBootloader::class, // Optional, to generate Centrifugo handlers and TCP services via Scaffolder RoadRunnerBridge\CommandBootloader::class, // ... ];
Usage
TCP
RoadRunner includes TCP server and can be used to replace classic TCP setup with much greater performance and flexibility.
Bootloader
Add Spiral\RoadRunnerBridge\Bootloader\TcpBootloader to application bootloaders list:
use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge; protected const LOAD = [ // ... RoadRunnerBridge\TcpBootloader::class, // ... ];
This bootloader adds a dispatcher and necessary services for TCP to work.
Also, using the addService and addInterceptors methods can dynamically add services to TCP servers and configure
interceptors.
Configuration
Configure tcp section in the RoadRunner .rr.yaml configuration file with needed TCP servers. Example:
tcp: servers: smtp: addr: tcp://127.0.0.1:22 delimiter: "\r\n" # by default monolog: addr: tcp://127.0.0.1:9913 pool: num_workers: 2 max_jobs: 0 allocate_timeout: 60s destroy_timeout: 60s
Create configuration file app/config/tcp.php. In the configuration, it's required to specify the services that
will handle requests from a specific TCP server. Optionally, interceptors can be added for each specific server.
With the help there, can add some logic before handling the request in service. Configuration example:
<?php declare(strict_types=1); return [ /** * Services for each server. */ 'services' => [ 'smtp' => SomeService::class, 'monolog' => OtherService::class ], /** * Interceptors, this section is optional. * @see https://spiral.dev/docs/cookbook-domain-core/2.8/en#core-interceptors */ 'interceptors' => [ // several interceptors 'smtp' => [ SomeInterceptor::class, OtherInterceptor::class ], 'monolog' => SomeInterceptor::class // one interceptor ], 'debug' => env('TCP_DEBUG', false) ];
Services
A service must implement the interface Spiral\RoadRunnerBridge\Tcp\Service\ServiceInterface with one required
method handle.
After processing a request, the handle method must return the Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface
object
with result (RespondMessage, CloseConnection, ContinueRead).
Example:
<?php declare(strict_types=1); namespace App\Tcp\Service; use Spiral\RoadRunner\Tcp\Request; use Spiral\RoadRunnerBridge\Tcp\Response\RespondMessage; use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface; use Spiral\RoadRunnerBridge\Tcp\Service\ServiceInterface; class TestService implements ServiceInterface { public function handle(Request $request): ResponseInterface { // some logic return new RespondMessage('some message', true); } }
The service can be generated using the Scaffolder component. Make sure that bootloader
Spiral\RoadRunnerBridge\Bootloader\ScaffolderBootloader is added in your application and run:
php app.php create:tcp-service Test
This will generate service TestService in the folder Endpoint/Tcp/Service/TestService.php.
Note Namespace (and generation path) can be configured. Read more about Scaffolder component.
Note Read more about RoadRunner configuration on official site https://roadrunner.dev.
License:
MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.
spiral/roadrunner-bridge 适用场景与选型建议
spiral/roadrunner-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.92M 次下载、GitHub Stars 达 64, 最近一次更新时间为 2022 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 spiral/roadrunner-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spiral/roadrunner-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.92M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 64
- 点击次数: 14
- 依赖项目数: 11
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-19