php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19746 SAPI-CLI fread/fgets on STDIN problem
Submitted: 2002-10-03 19:17 UTC Modified: 2002-10-05 13:56 UTC
From: mreddin at nii dot net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4CVS-2002-10-03 OS: Redhat 7.3 i386
Private report: No CVE-ID: None
 [2002-10-03 19:17 UTC] mreddin at nii dot net
In trying to take user input from Shell in the last two CVS snapshots using the SAPI-CLI, the following program [and many variations thereof] hang on STDIN [basically it takes unlimited input as if its not recognizing EOL]. This is under an Pentium-2, Redhat 7.3 with the latest glibc library off Redhat's update site.

<?php
function getInput($length)
  {
            $fr = fopen("php://stdin", "r");
            $input = fgets($fr, $length);
            $input = rtrim($input);
            fclose($fr);
            return $input;
  }
echo "Enter some text (10 char max): ";
$text = getInput(10);
echo "You entered: $text\n";

?>

This program works fine on an older php CGI style binary but does not work under the current snapshot. Have also tried the manual suggestion of using the new constant STDIN and that causes the same behavior - hence my suspicion this is a bug.

Here is the modules compiled in

[root@league league]# php -m
[PHP Modules]
xml
tokenizer
standard
sockets
session
posix
pcre
pcntl
overload
mysql
mbstring
gd
ctype
zlib

[Zend Modules]


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-04 12:11 UTC] iliaa@php.net
Marking this as critical, since the behaviour of this bug demonstrates a complete breakage of reading from stdin.
The current CVS buffers the read/gets calls, which causes script such as this sit on read() until the default buffer (8192 bytes) is read in.
 [2002-10-04 13:53 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2002-10-04 18:10 UTC] mreddin at nii dot net
This still does not work in snapshot:  php4-200210041500

Interestingly enough, the previous snapshot from 1200 hours worked better as it accepted STDIN up to the length of the buffer specified in the program but still did not recognize any EOL prior to reaching that buffer, now its back to the original behavior. If this behavior continues after a couple more SNAPS I will reopen this report.
 [2002-10-04 18:12 UTC] iliaa@php.net
The intial fix did not quite as well as I had hoped. The problem is still there and is being worked upon.
 [2002-10-05 06:39 UTC] wez@php.net
I've committed a fix for this this morning.
Please try either a snapshot (you might have to wait a
couple of hours for it to be generated), or check it right
out of CVS.

--Wez.
 [2002-10-05 13:56 UTC] mreddin at nii dot net
Nice job, works as expected now.  Bug ticket closed, thanks again.

Mike
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC