phasync
StringBuffer / readFixed

Method

StringBuffer::readFixed

Returns exactly $length bytes, and waits until that many are buffered.

Description#

public StringBuffer::readFixed(
    int $length,
    float $timeout = PHP_FLOAT_MAX
): ?string

Returns null if the buffer ends with fewer than $length bytes left; they stay in the buffer. A $timeout of 0 never waits: it returns null when $length bytes are not there yet.

Parameters#

$length int
The number of bytes
$timeout float = PHP_FLOAT_MAX
Seconds to wait at most

Return values#

The bytes, or null at the end of the buffer ?string

Errors / Exceptions#

ExceptionWhen
TimeoutExceptionIf $length bytes were not there in time
DeadmanExceptionIf the writer exited without ending the buffer

See also#