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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: an0nym at narod dot ru
New email:
PHP Version: OS:

 

 [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: Wed Apr 24 18:01:28 2024 UTC