Awesome
chubbyphp-workerman-request-handler
Description
A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17.
Requirements
- php: ^8.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
- workerman/workerman: ^4.1.13
Installation
Through Composer as chubbyphp/chubbyphp-workerman-request-handler.
composer require chubbyphp/chubbyphp-workerman-request-handler "^2.1"
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