chubbyphp / chubbyphp-swoole-request-handler
A request handler adapter for swoole, using PSR-7, PSR-15 and PSR-17.
Installs: 10 919
Dependents: 2
Suggesters: 0
Security: 0
Stars: 26
Watchers: 5
Forks: 3
Open Issues: 0
Requires
- php: ^8.1
- ext-swoole: ^5.1.1
- dflydev/fig-cookies: ^3.1
- psr/http-factory: ^1.0.2
- psr/http-message: ^1.1|^2.0
- psr/http-server-handler: ^1.0.2
- psr/log: ^2.0|^3.0
Requires (Dev)
- blackfire/php-sdk: ^2.3.5
- chubbyphp/chubbyphp-dev-helper: dev-master
- chubbyphp/chubbyphp-mock: ^1.7
- infection/infection: ^0.27.8
- php-coveralls/php-coveralls: ^2.7
- phpstan/extension-installer: ^1.3.1
- phpstan/phpstan: ^1.10.45
- phpunit/phpunit: ^10.4.2
- swoole/ide-helper: ^5.1
README
Description
A request handler adapter for swoole, using PSR-7, PSR-15 and PSR-17.
Requirements
- php: ^8.1
- ext-swoole: ^5.1.1
- dflydev/fig-cookies: ^3.1
- psr/http-factory: ^1.0.2
- psr/http-message: ^1.1|^2.0
- psr/http-server-handler: ^1.0.2
- psr/log: ^2.0|^3.0
Installation
Through Composer as chubbyphp/chubbyphp-swoole-request-handler.
composer require chubbyphp/chubbyphp-swoole-request-handler "^1.3"
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