php.net |  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
Votes:2
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:
MUST BE VALID
Solve the problem:
24 - 2 = ?
Subscribe to this entry?

 
 [2013-12-26 10:12 UTC] an0nym at narod dot ru
Description:
------------
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 
<?php
fwrite(STDOUT, 'test1');
sleep(5);
fwrite(STDOUT, "\n");
sleep(5);
fwrite(STDOUT, "test2\n");
$ cat test2.php 
<?php
stream_set_blocking(STDIN, false);
do {
    $test = fgets(STDIN);
    if ($test) {
        var_dump($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
"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2014-01-05 09:32 UTC] krakjoe@php.net
Anything in non-blocking mode will return if the stream would block.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 00:01:30 2024 UTC