php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29663 php://stdin does not wait for input after first run
Submitted: 2004-08-13 21:22 UTC Modified: 2005-02-12 09:54 UTC
From: tomsommer@php.net Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.0.1 OS: Win32 & Linux
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: tomsommer@php.net
New email:
PHP Version: OS:

 

 [2004-08-13 21:22 UTC] tomsommer@php.net
Description:
------------
The code below works in PHP4, but not in PHP 5.0.1

After first being prompted for stdin input and clicking enter the rest of the loop finishes without waiting for user interaction

Run the code below in CLI.
Enter "foo"[ENTER]

Reproduced in both Win32 and Linux

Reproduce code:
---------------
<?php
    for($i = 0; $i <= 10; $i++ ) {
        echo 'Please enter a number: ';
        $fp = fopen('php://stdin', 'r');
        $answr = trim(fgets($fp, 1024));
        var_dump($answr);
        fclose($fp);
    }
?>

Expected result:
----------------
Please enter something: foo
string(3) "foo"
Please enter something: 

Actual result:
--------------
Please enter something: foo
string(3) "foo"
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""
Please enter something: string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-13 21:40 UTC] tomsommer@php.net
Using the STDIN constant works.
Removing fclose() in the above example does not solve the problem.
 [2004-08-13 22:42 UTC] tomsommer@php.net
Apparently this in intended behaviour for CLI scripts.
 [2005-02-12 04:04 UTC] cellog@php.net
This is a major BC break with PHP 4, and breaks the PEAR installer's PEAR_Frontend_CLI::userDialog() function.

I strongly suggest reconsidering the "bogus" mark
 [2005-02-12 09:54 UTC] wez@php.net
Sorry Greg, it's not going to change (plus it's already in the wild; you'll need to fix PEAR regardless).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 02:01:38 2025 UTC