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.
Synopsis
Section titled “Synopsis”final class SwooleResponseEmitter implements ResponseEmitterInterface
| Implements | ResponseEmitterInterface |
| Source | SwooleResponseEmitter.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(SwooleResponseWriterInterface $writer): mixed
| Parameter | Type | Description |
|---|---|---|
$writer | SwooleResponseWriterInterface |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
emit(ResponseInterface $response): void | Writes status, headers and body onto Swoole’s response object. |
supportsStreaming(): bool | Always true: Swoole’s write() delivers a chunk without buffering the whole body. |
emit()
Section titled “emit()”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.
| Parameter | Type | Description |
|---|---|---|
$response | ResponseInterface |
supportsStreaming()
Section titled “supportsStreaming()”public function supportsStreaming(): bool
Always true: Swoole’s write() delivers a chunk without buffering the whole body.
Returns bool