phasync
StringBuffer / read

Method

StringBuffer::read

Returns up to $maxLength bytes, and waits while the buffer is empty and not ended.

Description#

public StringBuffer::read(
    int $maxLength,
    float $timeout = PHP_FLOAT_MAX
): string

Returns what is buffered when there is any, which may be less than $maxLength, and an empty string once the buffer has ended and is empty. A $timeout of 0 never waits: it returns what is buffered, possibly an empty string.

Parameters#

$maxLength int
The most bytes to return
$timeout float = PHP_FLOAT_MAX
Seconds to wait for data at most

Return values#

The bytes read string

Errors / Exceptions#

ExceptionWhen
OutOfBoundsExceptionIf $maxLength is negative
TimeoutExceptionIf no data arrived in time
DeadmanExceptionIf the writer exited without ending the buffer, once the buffered data is read

See also#