Page MenuHomePhorge
Diviner Arcanist Tech Docs phutil_fwrite_nonblocking_stream

function phutil_fwrite_nonblocking_stream($stream, $bytes)
Arcanist Technical Documentation ()

Perform an fwrite() which distinguishes between EAGAIN and EPIPE.

PHP's fwrite() is broken, and never returns false for writes to broken nonblocking pipes: it always returns 0, and provides no straightforward mechanism for distinguishing between EAGAIN (buffer is full, can't write any more right now) and EPIPE or similar (no write will ever succeed).

See: https://bugs.php.net/bug.php?id=39598

If you call this method instead of fwrite(), it will attempt to detect when a zero-length write is caused by EAGAIN and return 0 only if the write really should be retried.

Parameters
resource$streamSocket or pipe stream.
string$bytesBytes to write.
Return
bool|intNumber of bytes written, or `false` on any error (including errors which `fwrite()` can not detect, like a broken pipe).