Symfony

Give each request a fresh Symfony kernel. This keeps overlapping requests in the same worker from sharing a kernel.

Install the package

Shell
composer require 'mini4work/webserver:^1.8' symfony/http-kernel symfony/http-foundation symfony/event-dispatcher

Write a handler

Save this as server.php next to vendor/.

PHP
<?php

declare(strict_types=1);

use M4W\WebServer\Adapters\Symfony\KernelRequestHandler;
use M4W\WebServer\Cli\ServerCommand;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelEvents;

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

$handler = new KernelRequestHandler(static function () {
    $events = new EventDispatcher;
    $events->addListener(KernelEvents::REQUEST, static function (RequestEvent $event): void {
        $request = $event->getRequest();
        $event->setResponse($request->getPathInfo() === '/hello'
            ? new Response('Hello '.$request->cookies->get('name', 'guest'))
            : new Response('', 404));
    });

    return new HttpKernel($events, new ControllerResolver);
});

exit((new ServerCommand)->run($argv ?? [__FILE__], $handler));

Start the server

Save this as m4w.json next to server.php.

JSON
{
  "listen": { "port": 9000 },
  "protocols": { "http": "1.1" },
  "tls": { "mode": "off" },
  "workers": { "count": 1 }
}
Shell
php server.php m4w.json

Send a request from a second terminal.

Shell
curl -i -X POST --cookie 'name=Ada' http://127.0.0.1:9000/hello

HTTP/1.1 200 OK · Hello Ada

Request state

HttpFoundation receives the query, cookies and uploaded files. For HTTP/2 and HTTP/3, :authority supplies Host. Pseudo-headers and names containing underscores are excluded when mapping headers to PHP server variables.

In a FrameworkBundle project, use your application kernel factory. Non-multipart input is buffered in memory (1 MiB by default). MultipartOptions controls fields and uploads separately.

PHP
$handler = new KernelRequestHandler(
    static fn () => new \App\Kernel('prod', false),
    maxBodyBytes: 1_048_576,
    maxResponseBytes: 67_108_864,
);

The response limit defaults to 64 MiB. StreamedResponse and BinaryFileResponse write synchronously to a temporary file before sending. Use finite responses here. Live SSE needs a different transport path.

When the body closes on completion or cancellation, the adapter terminates a terminable kernel with its response, resets services and shuts down a FrameworkBundle kernel. A component kernel can implement ResetInterface. Cleanup must not suspend. Body close does not confirm delivery to the client.