项目作者: chubbyphp

项目描述 :
A request handler adapter for swoole, using PSR-7, PSR-15 and PSR-17.
高级语言: PHP
项目地址: git://github.com/chubbyphp/chubbyphp-swoole-request-handler.git
创建时间: 2019-07-28T17:39:17Z
项目社区:https://github.com/chubbyphp/chubbyphp-swoole-request-handler

开源协议:MIT License

下载


chubbyphp-swoole-request-handler

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 swoole, using PSR-7, PSR-15 and PSR-17.

Requirements

Installation

Through Composer as chubbyphp/chubbyphp-swoole-request-handler.

  1. composer require chubbyphp/chubbyphp-swoole-request-handler "^1.5"

Usage

  1. <?php
  2. declare(strict_types=1);
  3. namespace App;
  4. use Chubbyphp\SwooleRequestHandler\OnRequest;
  5. use Chubbyphp\SwooleRequestHandler\PsrRequestFactory;
  6. use Chubbyphp\SwooleRequestHandler\SwooleResponseEmitter;
  7. use Psr\Http\Server\RequestHandlerInterface;
  8. use Some\Psr17\Factory\ServerRequestFactory;
  9. use Some\Psr17\Factory\StreamFactory;
  10. use Some\Psr17\Factory\UploadedFileFactory;
  11. use Swoole\Http\Server;
  12. $loader = require __DIR__.'/vendor/autoload.php';
  13. /** @var RequestHandlerInterface $app*/
  14. $app = ...;
  15. $http = new Server('0.0.0.0', 8080);
  16. $http->on('start', function (Server $server): void {
  17. echo 'Swoole http server is started at http://0.0.0.0:8080'.PHP_EOL;
  18. });
  19. $http->on('request', new OnRequest(
  20. new PsrRequestFactory(
  21. new ServerRequestFactory(),
  22. new StreamFactory(),
  23. new UploadedFileFactory()
  24. ),
  25. new SwooleResponseEmitter(),
  26. $app
  27. ));
  28. $http->start();

with blackfire

  1. <?php
  2. declare(strict_types=1);
  3. namespace App;
  4. use Blackfire\Client;
  5. use Chubbyphp\SwooleRequestHandler\Adapter\BlackfireOnRequestAdapter;
  6. use Chubbyphp\SwooleRequestHandler\OnRequest;
  7. /** @var OnRequest $onRequest */
  8. $onRequest = ...;
  9. if (extension_loaded('blackfire') {
  10. $onRequest = new BlackfireOnRequestAdapter($onRequest, new Client());
  11. }
  12. $http->on('request', $onRequest);

with newrelic

  1. <?php
  2. declare(strict_types=1);
  3. namespace App;
  4. use Chubbyphp\SwooleRequestHandler\Adapter\NewRelicOnRequestAdapter;
  5. use Chubbyphp\SwooleRequestHandler\OnRequest;
  6. /** @var OnRequest $onRequest */
  7. $onRequest = ...;
  8. if (extension_loaded('newrelic') && false !== $name = ini_get('newrelic.appname')) {
  9. $onRequest = new NewRelicOnRequestAdapter($onRequest, $name);
  10. }
  11. $http->on('request', $onRequest);

2025 Dominik Zogg