From:             max at nucleus dot it
Operating system: Linux
PHP version:      5.2.0
PHP Bug Type:     Streams related
Bug description:  error verification after fwrite()

Description:
------------
The documentation states tha fwrite() returns false in 
case of error, but it doesn't do so if the actual write 
fails.
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 
errno.

Reproduce code:
---------------
$Proc = proc_open($Cmd, $Streams, $Pipes, $CWD, $Env);

stream_set_blocking($Pipes[0], 0);

$Result = fwrite($Pipes[0], "test");

// If $Pipes[0] 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.

Expected result:
----------------
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.


-- 
Edit bug report at http://bugs.php.net/?id=39598&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39598&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39598&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39598&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39598&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39598&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39598&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39598&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39598&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39598&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39598&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39598&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39598&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39598&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39598&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39598&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39598&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39598&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39598&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39598&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39598&r=mysqlcfg

Reply via email to