chubbyphp / chubbyphp-swoole-request-handler
A request handler adapter for swoole, using PSR-7, PSR-15 and PSR-17.
Installs: 11 047
Dependents: 1
Suggesters: 0
Security: 0
Stars: 26
Watchers: 5
Forks: 4
Open Issues: 1
Requires
- php: ^8.2
- ext-swoole: ^5.1.6|6.0.0-RC1|^6.0
- dflydev/fig-cookies: ^3.1
- psr/http-factory: ^1.1
- psr/http-message: ^1.1|^2.0
- psr/http-server-handler: ^1.0.2
- psr/log: ^2.0|^3.0.2
Requires (Dev)
- blackfire/php-sdk: ^2.5.4
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-mock: ^1.8
- infection/infection: ^0.29.8
- php-coveralls/php-coveralls: ^2.7
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.0.3
- phpunit/phpunit: ^11.5.0
- swoole/ide-helper: ^5.1.6|^6.0.0-RC1|^6.0
README
Description
A request handler adapter for swoole, using PSR-7, PSR-15 and PSR-17.
Requirements
- php: ^8.2
- ext-swoole: ^5.1.6|6.0.0-RC1|^6.0
- dflydev/fig-cookies: ^3.1
- psr/http-factory: ^1.1
- psr/http-message: ^1.1|^2.0
- psr/http-server-handler: ^1.0.2
- psr/log: ^2.0|^3.0.2
Installation
Through Composer as chubbyphp/chubbyphp-swoole-request-handler.
composer require chubbyphp/chubbyphp-swoole-request-handler "^1.5"
Usage
<?php declare(strict_types=1); namespace App; use Chubbyphp\SwooleRequestHandler\OnRequest; use Chubbyphp\SwooleRequestHandler\PsrRequestFactory; use Chubbyphp\SwooleRequestHandler\SwooleResponseEmitter; use Psr\Http\Server\RequestHandlerInterface; use Some\Psr17\Factory\ServerRequestFactory; use Some\Psr17\Factory\StreamFactory; use Some\Psr17\Factory\UploadedFileFactory; use Swoole\Http\Server; $loader = require __DIR__.'/vendor/autoload.php'; /** @var RequestHandlerInterface $app*/ $app = ...; $http = new Server('0.0.0.0', 8080); $http->on('start', function (Server $server): void { echo 'Swoole http server is started at http://0.0.0.0:8080'.PHP_EOL; }); $http->on('request', new OnRequest( new PsrRequestFactory( new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory() ), new SwooleResponseEmitter(), $app )); $http->start();
with blackfire
<?php declare(strict_types=1); namespace App; use Blackfire\Client; use Chubbyphp\SwooleRequestHandler\Adapter\BlackfireOnRequestAdapter; use Chubbyphp\SwooleRequestHandler\OnRequest; /** @var OnRequest $onRequest */ $onRequest = ...; if (extension_loaded('blackfire') { $onRequest = new BlackfireOnRequestAdapter($onRequest, new Client()); } $http->on('request', $onRequest);
with newrelic
<?php declare(strict_types=1); namespace App; use Chubbyphp\SwooleRequestHandler\Adapter\NewRelicOnRequestAdapter; use Chubbyphp\SwooleRequestHandler\OnRequest; /** @var OnRequest $onRequest */ $onRequest = ...; if (extension_loaded('newrelic') && false !== $name = ini_get('newrelic.appname')) { $onRequest = new NewRelicOnRequestAdapter($onRequest, $name); } $http->on('request', $onRequest);
Copyright
2024 Dominik Zogg