phasync\Psr\UnbufferedStream class

Documentation

Unbuffered streaming PSR-7 StreamInterface

Designed for returning a response which has not been completed yet. A coroutine can continue appending to the stream.

Usage:

$s = new UnbufferedStream();

// Create a coroutine which appends to the stream
phasync::go(function() use ($s) {
    // Append chunks as much as you need
    $s->append("A chunk");

    // Signal that the stream is complete
    $s->end();
});

// Return the stream
return $response->withStream($s);

By default the stream will buffer up to 64 KB of data, to improve performance and reduce context switching.

Inheritance

Implements: Psr\Http\Message\StreamInterface Stringable

Properties (11)

private string $buffer

The string buffer

private int $bufferSize
private int $readOffset
private float $deadlockTimeout
private bool $closed
private bool $ended
private bool $locked
private bool $detached
private WeakReference $creator
private object $readFlag
private object $writeFlag

Methods (18)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Append more data to the stream

Inform that no more content will be appended to the stream,

Source

src/Psr/UnbufferedStream.php:37-234