chubbyphp / chubbyphp-workerman-request-handler
A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17.
Installs: 10 791
Dependents: 2
Suggesters: 0
Security: 0
Stars: 11
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.2
- 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
- workerman/workerman: ^4.2.1
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
README
Description
A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17.
Requirements
- php: ^8.2
- 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
- workerman/workerman: ^4.2.1
Installation
Through Composer as chubbyphp/chubbyphp-workerman-request-handler.
composer require chubbyphp/chubbyphp-workerman-request-handler "^2.2"
Usage
<?php declare(strict_types=1); namespace App; use Chubbyphp\WorkermanRequestHandler\OnMessage; use Chubbyphp\WorkermanRequestHandler\PsrRequestFactory; use Chubbyphp\WorkermanRequestHandler\WorkermanResponseEmitter; use Psr\Http\Server\RequestHandlerInterface; use Some\Psr17\Factory\ServerRequestFactory; use Some\Psr17\Factory\StreamFactory; use Some\Psr17\Factory\UploadedFileFactory; use Workerman\Worker; $loader = require __DIR__.'/vendor/autoload.php'; /** @var RequestHandlerInterface $app*/ $app = ...; $http = new Worker('http://0.0.0.0:8080'); $http->count = 4; $http->onWorkerStart = function () { echo 'Workerman http server is started at http://0.0.0.0:8080'.PHP_EOL; }; $http->onMessage = new OnMessage( new PsrRequestFactory( new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory() ), new WorkermanResponseEmitter(), $app ); Worker::runAll();
with blackfire
<?php declare(strict_types=1); namespace App; use Blackfire\Client; use Chubbyphp\WorkermanRequestHandler\Adapter\BlackfireOnMessageAdapter; use Chubbyphp\WorkermanRequestHandler\OnMessage; /** @var OnMessage $onMessage */ $onMessage = ...; if (extension_loaded('blackfire') { $onMessage = new BlackfireOnMessageAdapter($onMessage, new Client()); } $http->onMessage = $onMessage;
with newrelic
<?php declare(strict_types=1); namespace App; use Chubbyphp\WorkermanRequestHandler\Adapter\NewRelicOnMessageAdapter; use Chubbyphp\WorkermanRequestHandler\OnMessage; /** @var OnMessage $onMessage */ $onMessage = ...; if (extension_loaded('newrelic') && false !== $name = ini_get('newrelic.appname')) { $onMessage = new NewRelicOnMessageAdapter($onMessage, $name); } $http->onMessage = $onMessage;
Copyright
2024 Dominik Zogg