chubbyphp/chubbyphp-workerman-request-handler

A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17.

2.1.0 2023-12-03 20:11 UTC

This package is auto-updated.

Last update: 2024-07-13 20:45:36 UTC


README

CI Coverage Status Mutation testing badge Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17.

Requirements

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