|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2002-03-13 17:29 UTC] pjm at cctechnol dot com
  [2002-07-01 15:10 UTC] sander@php.net
  [2002-07-01 15:13 UTC] sander@php.net
  [2002-07-01 15:15 UTC] sander@php.net
  [2002-08-02 01:00 UTC] php-bugs at lists dot php dot net
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 22:00:01 2025 UTC | 
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