使 Workerman 与任何 PSR-7 项目兼容

dev-master 2021-10-22 15:15 UTC

This package is auto-updated.

Last update: 2024-09-22 22:06:34 UTC


README

此项目处于测试阶段。

Workerman 是一个高性能的异步事件驱动 PHP 框架,用于构建快速且可扩展的网络应用程序。Workerman 支持 HTTP、Websocket、SSL 以及其他自定义协议。Workerman 支持事件扩展。

它做什么

它将 Workerman 框架中的所有 http 变量传递到目标 PSR-7 项目,让您能够专注于 PSR-7。

使用 Slim 的 Hello World

<?php

declare(strict_types=1);

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Factory\AppFactory;
use Psr7Workerman\Worker;

require __DIR__ . '/vendor/autoload.php';

$app = AppFactory::create();
$app->get('/', function ($request, $response, $args) {
    $response->getBody()->write('Hello World!!!');
    return $response;
});
$worker = new Worker('http://127.0.0.1:1234');
$worker->onMessage(function (ServerRequestInterface $request) use ($app): ResponseInterface {
    return $app->handle($request);
});
$worker->runAll();

然后运行 php start.php start

基准测试

使用 PHP-FPM 的 Slim Hello World 和不使用事件库的 Workerman。

许可证

MIT 许可证与 SATA 许可证

SATA 许可证(星号和感谢作者许可证)

使用此项目(包括代码/docs/...),您应首先在上述项目 URL 部分中的项目星星+/1/点赞/,然后感谢作者在版权部分。