diff --git a/packages/workerman-symfony-runtime/OnMessage.php b/packages/workerman-symfony-runtime/OnMessage.php new file mode 100644 index 0000000..c7380a1 --- /dev/null +++ b/packages/workerman-symfony-runtime/OnMessage.php @@ -0,0 +1,44 @@ +requestHander->handle( + $this->psrRequestFactory->create($workermanTcpConnection, $workermanRequest), + ); + + $workermanTcpConnection->send( + (new WorkermanResponse()) + ->withStatus($response->getStatusCode(), $response->getReasonPhrase()) + ->withHeaders($response->getHeaders()) + ->withBody((string) $response->getBody()), + ); + + $keepAlive = in_array('keep-alive', explode(',', strtolower($workermanRequest->header('connection', 'close'))), true); + if (! $keepAlive) { + $workermanTcpConnection->close(); + } + } +} diff --git a/packages/workerman-symfony-runtime/Resources/config/services.php b/packages/workerman-symfony-runtime/Resources/config/services.php index 35a17b9..35fb32c 100644 --- a/packages/workerman-symfony-runtime/Resources/config/services.php +++ b/packages/workerman-symfony-runtime/Resources/config/services.php @@ -4,13 +4,11 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; -use Chubbyphp\WorkermanRequestHandler\OnMessage; use Chubbyphp\WorkermanRequestHandler\OnMessageInterface; use Chubbyphp\WorkermanRequestHandler\PsrRequestFactory; use Chubbyphp\WorkermanRequestHandler\PsrRequestFactoryInterface; -use Chubbyphp\WorkermanRequestHandler\WorkermanResponseEmitter; -use Chubbyphp\WorkermanRequestHandler\WorkermanResponseEmitterInterface; use Manyou\WorkermanSymfonyRuntime\HeaderNameMapper; +use Manyou\WorkermanSymfonyRuntime\OnMessage; use Manyou\WorkermanSymfonyRuntime\SymfonyRequestHandler; use Psr\Http\Server\RequestHandlerInterface; use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; @@ -50,8 +48,6 @@ // Workerman Request to PSR Request $services->set(PsrRequestFactoryInterface::class, PsrRequestFactory::class); - $services->set(WorkermanResponseEmitterInterface::class, WorkermanResponseEmitter::class); - $services->set(SymfonyRequestHandler::class) ->arg(HttpKernelInterface::class, service('kernel')); diff --git a/packages/workerman-symfony-runtime/Runtime.php b/packages/workerman-symfony-runtime/Runtime.php index 4112a36..89ccfa9 100644 --- a/packages/workerman-symfony-runtime/Runtime.php +++ b/packages/workerman-symfony-runtime/Runtime.php @@ -23,12 +23,12 @@ public function __construct(array $options = []) $this->socket = $options['socket'] ?? $_SERVER['APP_RUNTIME_SOCKET'] ?? $_ENV['APP_RUNTIME_SOCKET'] - ?? 'http://0.0.0.0:' . ($_SERVER['PORT'] ?? $_ENV['PORT'] ?? 8283); + ?? 'http://0.0.0.0:' . ($_SERVER['PORT'] ?? $_ENV['PORT'] ?? 3000); $this->workers = (int) ($options['workers'] ?? $_SERVER['APP_RUNTIME_WORKERS'] ?? $_ENV['APP_RUNTIME_WORKERS'] - ?? 1); + ?? 16); $hash = md5(__FILE__);