php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39598 error verification after fwrite()
Submitted: 2006-11-22 22:53 UTC Modified: 2006-11-22 23:06 UTC
Votes:7
Avg. Score:5.0 ± 0.0
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:4 (57.1%)
From: max at nucleus dot it Assigned:
Status: Open Package: Feature/Change Request
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-11-22 22:53 UTC] max at nucleus dot it
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-01 00:04 UTC] gauthierm@php.net
Here's a simple reproduce test case:

http://labs.silverorange.com/files/php-bug39598/php-bug-39598-test.phps

In this case, and EPIPE occurs. The fwrite call writes 0 bytes. No error code is 
available and no PHP error is raised.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 09:02:28 2014 UTC