Skip to content

SapiEmitter

Emits through the PHP SAPI: http_response_code(), header(), echo.

Correct for php-fpm, php -S and FrankenPHP worker mode alike — FrankenPHP is a real SAPI, so flushing inside a frankenphp_handle_request() callback reaches the client exactly as it does under FPM.

Not usable off-SAPI (RoadRunner, Swoole): under the CLI SAPI header() is a no-op and echo goes to the process’s stdout, which is the server’s protocol channel rather than the response body.

class SapiEmitter implements ResponseEmitterInterface

ImplementsResponseEmitterInterface
SourceRuntime/Emitter/SapiEmitter.php
MethodDescription
emit(ResponseInterface $response): voidSends the response through http_response_code(), header() and echo.
supportsStreaming(): boolAlways true: the SAPI can flush a body incrementally to the client.

public function emit(ResponseInterface $response): void

Sends the response through http_response_code(), header() and echo.

Any Content-Type already set on the SAPI is removed first, so an early fallback header cannot survive alongside the response’s own. Remaining headers are appended in order, allowing repeated names. An SseStream body is flushed event by event instead of being echoed in one piece.

ParameterTypeDescription
$responseResponseInterface

public function supportsStreaming(): bool

Always true: the SAPI can flush a body incrementally to the client.

Returns bool