Skip to content

SwooleResponseEmitter

Writes the response to Swoole’s per-request response object.

Constructed per request, unlike the SAPI and RoadRunner emitters, because the thing being written to is the current request’s response.

Swoole’s write() returning false is this runtime’s client-disconnect signal — the equivalent of connection_aborted() under a SAPI, which always reports 0 under the CLI and so cannot be used here. Without it an endless SSE generator would keep producing events for a client that has already gone.

final class SwooleResponseEmitter implements ResponseEmitterInterface

ImplementsResponseEmitterInterface
SourceSwooleResponseEmitter.php

public function __construct(SwooleResponseWriterInterface $writer): mixed

ParameterTypeDescription
$writerSwooleResponseWriterInterface

Returns mixed

MethodDescription
emit(ResponseInterface $response): voidWrites status, headers and body onto Swoole’s response object.
supportsStreaming(): boolAlways true: Swoole’s write() delivers a chunk without buffering the whole body.

public function emit(ResponseInterface $response): void

Writes status, headers and body onto Swoole’s response object.

A header with several values is passed as an array so repeated names (Set-Cookie) survive. For an SseStream body, Content-Length is dropped and the body is written chunk by chunk until the stream ends or the client goes away, with a final end() closing the response either way.

ParameterTypeDescription
$responseResponseInterface

public function supportsStreaming(): bool

Always true: Swoole’s write() delivers a chunk without buffering the whole body.

Returns bool