phasync
StringBuffer / write

Method

StringBuffer::write

Appends $chunk to the buffer, and wakes the reader.

Description#

public StringBuffer::write(
    string $chunk,
    float $timeout = PHP_FLOAT_MAX
): void

With a $maxSize and that much data unread, it waits until the reader has consumed enough. A $timeout of 0 never waits and writes past $maxSize, so the limit is backpressure and not a ceiling.

Parameters#

$chunk string
The bytes to append
$timeout float = PHP_FLOAT_MAX
Seconds to wait for room at most

Errors / Exceptions#

ExceptionWhen
RuntimeExceptionIf the buffer has ended
TimeoutExceptionIf there was no room in time

See also#

  • StringBuffer::endMarks the end of the stream: no more writes are accepted, and readers get the data left and then the end.