|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16048 fgets/feof failure when stdin is reading from a pipe
Submitted: 2002-03-13 17:00 UTC Modified: 2002-08-02 01:00 UTC
Avg. Score:4.4 ± 0.8
Reproduced:4 of 5 (80.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: pjm at cctechnol dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4.1.2 OS: Solaris 2.7 & 2.8
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.
Block user comment
Status: Assign to:
Bug Type:
From: pjm at cctechnol dot com
New email:
PHP Version: OS:


 [2002-03-13 17:00 UTC] pjm at cctechnol dot com
The fgets() function works differently when the input is a pipe.  Specifically, feof() returns true after the first line is read.  The test script and sample output follow.  The test script works fine if stdin is redirected from a file.  It fails if stdin is a pipe.

Nothing special about the build:

./configure  --prefix=/usr/local --with-mysql

pjm@poseidon> cat test.php 
#!/usr/local/bin/php -q

$fd = fopen("php://stdin", "r");
while (! feof($fd))
        $buffer = fgets($fd, 4096);
        echo $buffer;

pjm@poseidon> < test.php ./test.php 
#!/usr/local/bin/php -q

$fd = fopen("php://stdin", "r");
while (! feof($fd))
        $buffer = fgets($fd, 4096);
        echo $buffer;

pjm@poseidon> cat test.php | ./test.php 
#!/usr/local/bin/php -q


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-13 17:29 UTC] pjm at cctechnol dot com
I also tested this on Red Hat 7.2 with PHP 4.0.6  It works fine there.
 [2002-07-01 15:10 UTC]
Can't reproduce with the latest CVS. Can you try a snapshot from to see if it's been fixed?
 [2002-07-01 15:13 UTC]
This is actually a dupe of #8849. Please try the snapshot anyway but add your experiences to #8849. Thanks.
 [2002-07-01 15:15 UTC]
Sorry, I'm crazy tonight... #18022 is a dupe of this one...

Just noting this url from #18022:
 [2002-08-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Mar 05 20:01:24 2021 UTC