go to bug id or search bugs for
The documentation states tha fwrite() returns false in
case of error, but it doesn't do so if the actual write
For example if I asynchronously write to a pipe (such as
those obtained by proc_open()) I and the pipe is not ready
or is broken, fwrite() returns 0.
This could be a correct behaviour it I had a way to
determine the error.
The problem is that EAGAIN or EPIPE are completely
impossible to determine and I can't know if I need to wait
or I have to close the stream.
A possible solution would be to implement ferror() or
$Proc = proc_open($Cmd, $Streams, $Pipes, $CWD, $Env);
$Result = fwrite($Pipes, "test");
// If $Pipes is not ready to receive data
// $Result is 0, but I can't know why.
// The real code I'm writing involves
// stream_select() and repeated reads and writes
// on multiple pipes.
fwrite() should return 0 when the stream is asynchrounous,
the C write() returns 0 and errno is EAGAIN.
fwrite() should return false in all other cases where the
C write() returns 0.
Alternatively a way to access ferror() or errno is needed.
Add a Patch
Add a Pull Request
Here's a simple reproduce test case:
In this case, and EPIPE occurs. The fwrite call writes 0 bytes. No error code is
available and no PHP error is raised.
Missing error detection in streams and filters is a general flaw in the internal i/o handling affecting all the related functions (fopen, fread, fwrite, fflush, fclose) which is really severe, because it affects the safety of any file and data transfer, and would deserve maximum attention and urgency for being fix asap. I may list several other reports that demonstrates missing detection of corrupted file system missing detection of invalid encoded data and so on:
fread() does not detect file access error
(Also includes disk image containing a damaged file for testing.)
require* and include* do not detect input/output error
(Probably related to the bug above.)
fread() does not detect decoding errors from filter zlib.inflate
(Probably missing propagation of errors through streams.)
fread() does not detects decoding errors from filter bzip2.decompress
(Probably the same as above.)
All these share the same common denominator: missing error propagation from libc to PHP user's space.