|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66353 fgets unexpected behaviour in non-blocking mode
Submitted: 2013-12-26 10:12 UTC Modified: 2014-01-05 09:32 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: an0nym at narod dot ru Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.5.7 OS: Linux, BSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
47 - 25 = ?
Subscribe to this entry?

 [2013-12-26 10:12 UTC] an0nym at narod dot ru
In non-blocking mode fgets should buffer data it read from stream until it meets eol or eof instead of returning anything it read. 

Test script:
$ cat test1.php 
fwrite(STDOUT, 'test1');
fwrite(STDOUT, "\n");
fwrite(STDOUT, "test2\n");
$ cat test2.php 
stream_set_blocking(STDIN, false);
do {
    $test = fgets(STDIN);
    if ($test) {
} while (!feof(STDIN));
$ php55 test1.php | php55 test2.php 

Expected result:
string(6) "test1
string(6) "test2

Actual result:
string(5) "test1"
string(1) "
string(6) "test2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-26 12:16 UTC] an0nym at narod dot ru
A more precise description: in non-blocking mode fgets should buffer data it read from stream and immediately return until it meets eol or eof.
 [2014-01-05 09:32 UTC]
-Status: Open +Status: Not a bug
 [2014-01-05 09:32 UTC]
Anything in non-blocking mode will return if the stream would block.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 05:01:28 2024 UTC