|  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: 2019-07-25 09:10 UTC
Avg. Score:4.6 ± 0.7
Reproduced:13 of 13 (100.0%)
Same Version:2 (15.4%)
Same OS:7 (53.8%)
From: max at nucleus dot it Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
 [2006-11-22 22:53 UTC] max at nucleus dot it
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 

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-01 00:04 UTC]
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.
 [2016-01-22 14:04 UTC] salsi at icosaedro dot it
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.
 [2018-06-30 20:24 UTC] novelesco at centrum dot cz
Please, at least fix the documentation.
 [2019-07-25 09:10 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2019-07-25 09:10 UTC]
In PHP 7.4 fwrite() will return 0 for EAGAIN/EWOULDBLOCK and false for other errors, in line with the requested behavior.
 [2021-07-02 10:05 UTC] davidsmithhello653 at gmail dot com
Worldwide Research and Development spending has arrived at almost 1.7 trillion USD. Nations have additionally swore to expand their private and public R&D spending and their number of scientists by 2030. Around the world, the Republic of Korea has the most noteworthy level of their GDP apportioned to R&D. While the United States has the most elevated spending by and large. 40% of the main 20 organizations with the most noteworthy spending on R&D in 2018 is made out of media transmission and tech organizations. 6 of the main 10 are data and innovation multimillion organizations; specifically, Amazon, Alphabet, Apple, Intel Co, Samsung, and Microsoft. In 2018, the Computing and Electronics industry and the Software and Internet industry remained in the best 5 ventures with the level of expenditure on innovative work around the world. Indeed, even the biggest of tech organizations and the most extravagant of nations comprehend R&D need and have put resources into the potential development that advancement brings them. When done adequately, item advancement turns into a vital driver for the development, even endurance, of a business. Innovative work patterns, for example, R&D patterns in programming advancement, interface together a few distinct parts of the business. Showcasing, Public Relations, Communication, and DevOps groups are a portion of the offices that cooperate to execute R&D activities and strategies. Techniques, for example, market investigation, item enhancements, and item and interaction improvement. With the right technique and R&D division, organizations can help group usefulness and proficiency and between departmental collaboration, check here for more information.With current devices like AI, AI, information science, and present day media transmission instruments, organizations can get enormous volumes of data from their customers to fuel their innovative work. Utilizing the data obtained and apparatuses like Data Analytics, Data Mining, Machine Learning, and other information preparing instruments and approaches, R&D offices can give information on item progress and execution. Leaders can acquire knowledge into their business and settle on better choices for the congruity of the organization.
 [2021-10-31 13:18 UTC] sheiladotis605 at gmail dot com
Whenever I saw this type of informative articles. Through this post you are discussing on max at nucleus dot it. Here people can be able to get decision about documentation states. All of smart owners want get this information to collect the detail of nucleus dot it. It is good to grow business but my more interest is in dedicated teams. These teams are getting training under experts they can do everything of their field. Customers are getting the service of these teams without any fear because they never charges any hidden charges. These teams have shared to spread something good for society. The value of these dedicated teams growing day by day because of increasing demand of various type of businesses. The member of dedicated teams are trained under expert. These teams have all ability to provide better solutions according to client's need. The help of dedicated teams means that the service of full development. cycle design, digital marketing and 24/7 service in only a one thing. These dedicated teams are just like a family of 100 family members. The main reason of increasing demand of dedicated teams is providing best results for their long time projects. This type of information is just like a good source of knowledge.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 02 02:01:26 2023 UTC