class Emitter implements EmitterInterface

Sends a response, streaming it only where streaming is what was asked for.

Nearly everything Flarum returns is a complete string that should be sent in one go, which is what {\Laminas\HttpHandlerRunner\Emitter\SapiEmitter} does. A handful of things — clearing the cache, which recompiles every asset and can run for half a minute — need to reach the browser as they happen, and for those the body is a {\Laminas\Diactoros\CallbackStream} whose callback writes and flushes progressively. The distinction is drawn on the body rather than a flag, because `SapiEmitter` would defeat a callback body anyway: it casts the stream to a string, which runs the callback to completion before a single byte is sent. Before streaming, PHP is told not to hold the body back itself: the output buffers `output_buffering` opens are closed, so the callback's `flush()` reaches the server, and `zlib.output_compression` is turned off, as it would gather the body to compress it. {\Flarum\Http\EventStream} builds such a response.

Methods

__construct( EmitterInterface $buffered = new SapiEmitter(), EmitterInterface $streamed = new SapiStreamEmitter(), Closure|null $prepareToStream = null)

No description

bool
emit( ResponseInterface $response)

No description

static void
prepareToStream()

Stops PHP holding a streamed body back. A buffer that already holds output is left alone, for the emitter to report as output sent too soon.

Details

__construct( EmitterInterface $buffered = new SapiEmitter(), EmitterInterface $streamed = new SapiStreamEmitter(), Closure|null $prepareToStream = null)

Parameters

EmitterInterface $buffered
EmitterInterface $streamed
Closure|null $prepareToStream Run before a streamed response is sent; PHP's own preparation unless given.

bool emit( ResponseInterface $response)

Parameters

ResponseInterface $response

Return Value

bool

static void prepareToStream()

Stops PHP holding a streamed body back. A buffer that already holds output is left alone, for the emitter to report as output sent too soon.

Return Value

void