php.net |  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
Votes:5
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
<?php

$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
<?php

$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


Patches

Pull Requests

History

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] sander@php.net
Can't reproduce with the latest CVS. Can you try a snapshot from http://snaps.php.net to see if it's been fixed?
 [2002-07-01 15:13 UTC] sander@php.net
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] sander@php.net
Sorry, I'm crazy tonight... #18022 is a dupe of this one...

Just noting this url from #18022:
http://marc.theaimsgroup.com/?l=php-general&m=101428004729977&w=2
 [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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC