antidot-fw/react-framework
Composer 安装命令:
composer require antidot-fw/react-framework
包简介
Antidot React Framework
README 文档
README
Requirements
- PHP ^7.4|^8.0
- Antidot Framework
- DriftPHP Server
- React Http
- React Promises
- Ramsey Uuid
Description
This package allows running asynchronous PHP following PSR-15 middleware standard approach.
Install
The preferred way to install this library is using the reactive-antidot-starter project.
composer create-project antidot-fw/reactive-antidot-starter
To install it on a existing Antidot Framework Project installation we need to tweak some configurations and replace or create new index.php file.
composer require antidot-fw/react-framework
Config
- Disable LaminasRequest Handler Runner
- Load Antidot React Config Provider after Antidot Framework provider
Example config from starter project
<?php // config/config.php declare(strict_types=1); use Antidot\DevTools\Container\Config\ConfigProvider as DevToolsConfigProvider; use Antidot\SymfonyConfigTranslator\Container\Config\ConfigAggregator; use Antidot\Yaml\YamlConfigProvider; use Laminas\ConfigAggregator\ArrayProvider; use Laminas\ConfigAggregator\PhpFileProvider; // To enable or disable caching, set the `ConfigAggregator::ENABLE_CACHE` boolean in // `config/autoload/local.php`. $cacheConfig = [ 'config_cache_path' => 'var/cache/config-cache.php', ]; $aggregator = new ConfigAggregator([ \WShafer\PSR11MonoLog\ConfigProvider::class, \Antidot\Event\Container\Config\ConfigProvider::class, \Antidot\Logger\Container\Config\ConfigProvider::class, \Antidot\Cli\Container\Config\ConfigProvider::class, \Antidot\Fast\Router\Container\Config\ConfigProvider::class, \Antidot\Container\Config\ConfigProvider::class, \Antidot\React\Container\Config\ConfigProvider::class, class_exists(DevToolsConfigProvider::class) ? DevToolsConfigProvider::class : fn() => [], new PhpFileProvider(realpath(__DIR__).'/services/{{,*.}prod,{,*.}local,{,*.}dev}.php'), new YamlConfigProvider(realpath(__DIR__).'/services/{{,*.}prod,{,*.}local,{,*.}dev}.yaml'), new ArrayProvider($cacheConfig), ], $cacheConfig['config_cache_path']); return $aggregator->getMergedConfig();
Default Config:
<?php $config = [ 'server' => [ 'host' => '0.0.0.0', 'port' => 5555, 'buffer_size' => 4096, 'max_concurrency' => 100, 'workers' => 1, 'static_folder' => 'public' ] ]
Usage
It allows executing promises inside PSR-15 and PSR-7 Middlewares and request handlers
PSR-15 Middleware
<?php declare(strict_types = 1); namespace App; use Antidot\React\PromiseResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; class SomeMiddleware implements MiddlewareInterface { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { return new PromiseResponse( resolve($request) ->then(static fn(ServerrequestInsterface $request) => $handler->handle($request)) ); } }
PSR-7 Request Handler
<?php declare(strict_types = 1); namespace App; use Antidot\React\PromiseResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; class SomeMiddleware implements RequestHandlerInterface { public function process(ServerRequestInterface $request): ResponseInterface { return resolve($request)->then( function(ServerrequestInterface $request): ResponseInterface { return new Response('Hello World!!!'); } );; } }
Server
Two new commands will be added to the Antidot Framework CLI tool, to allow running the application on top of Drift server
server:run: Run Drift HTTP Serverserver:watch: Watch Drift HTTP Server for development purposes
$ bin/console
...
server
server:run Run Drift HTTP Server
server:watch Watch Drift HTTP Server for development purposes
$ bin/console server:run -h Description: Run Drift HTTP Server Usage: server:run [options] [--] [<path>] Arguments: path The server will start listening to this address [default: "0.0.0.0:5555"] Options: --static-folder[=STATIC-FOLDER] Static folder path [default: "public"] --no-static-folder Disable static folder --debug Enable debug --no-header Disable the header --no-cookies Disable cookies --no-file-uploads Disable file uploads --concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 100] --request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 4096] --adapter[=ADAPTER] Server Adapter [default: "Antidot\React\DriftKernelAdapter"] --allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0] --workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 16] -q, --quiet Do not output any message
$ bin/console server:watch -h Description: Watch Drift HTTP Server for development purposes Usage: server:watch [options] [--] [<path>] Arguments: path The server will start listening to this address [default: "0.0.0.0:5555"] Options: --static-folder[=STATIC-FOLDER] Static folder path [default: "public"] --no-static-folder Disable static folder --debug Enable debug --no-header Disable the header --no-cookies Disable cookies --no-file-uploads Disable file uploads --concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 512] --request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 2048] --adapter[=ADAPTER] Server Adapter [default: "drift"] --allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0] --workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 1] -q, --quiet Do not output any message
antidot-fw/react-framework 适用场景与选型建议
antidot-fw/react-framework 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.33k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2021 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「react-php」 「psr-15」 「antidot-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 antidot-fw/react-framework 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 antidot-fw/react-framework 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 antidot-fw/react-framework 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Performant pure-PHP AMQP (RabbitMQ) non-blocking ReactPHP library
PHP port of charmbracelet/bubbletea — Elm-architecture TUI runtime.
Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library
PSR-11 container implementation made for Antidot Framework
A PSR-7 / PSR-15 compatible router interface and a PSR-15 server request handler implementation for routing.
Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library
统计信息
- 总下载量: 1.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2021-01-16