php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30154 php stdin control under windows dos prompt
Submitted: 2004-09-19 16:35 UTC Modified: 2004-09-21 04:20 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:3 (100.0%)
From: xxmettedraqxx at comcast dot net Assigned:
Status: Wont fix Package: CGI/CLI related
PHP Version: 5.0.1 OS: windows xp
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xxmettedraqxx at comcast dot net
New email:
PHP Version: OS:

 

 [2004-09-19 16:35 UTC] xxmettedraqxx at comcast dot net
Description:
------------
I'm not sure if non-blocking mode works under windows xp..

I can't seem to process anything while waiting for user input.. it's possible that I just do not know how to code this in php and it is my fault.  Although I searched for several days before posting this.

Can anyone help me out on this?

p.s. please email me if I don't respond.. I might loose track of this bug if I'm not contacted in some way.

Thank you.

Reproduce code:
---------------
set_time_limit (0);
$fp_stdin = fopen("php://stdin", "rb");
stream_set_blocking($fp_stdin, false);
ob_implicit_flush ();

$input = get_line($fp_stdin);

function get_line($fp) {
  $input = "";
  $char = "";
  do {
    if (($char = @fread($fp,1)) !== false) {
      $input .= $char;
      if ($char == "\n") { break; }
      $char = "";
    } else {
      echo "testing..\n";
    }
  } while(true);
  return $input;
}; // end function get_line

Expected result:
----------------
I should be able to see the word testing until the user types something.. as in.. say I typed in "shutdown"..

then the program would exit... after testing my input..

the testing is a substitute for checking telnet connections to allow for user input from the keyboard and at the same time run through other processes.

Actual result:
--------------
it waits for user input.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-20 15:44 UTC] xxmettedraq at comcast dot net
function getStdI() {

static $pStdn, $pArr; 

  if(!$pStdn || !$pArr) { 
    $pStdn = fopen("php://stdin", "r"); 
    $pArr = array($pStdn); 
  } 
  if (false === ($num_changed_streams = stream_select($pArr, $write = NULL, $except = NULL, 0))) {
    print("\$ 001 Socket Error : UNABLE TO WATCH STDIN.\n");
    return FALSE;
  } elseif ($num_changed_streams > 0) { 
    return fgets($pStdn, 1024);
  }
} // end function getStdI


I found this on the internet..

stream_select fails for me so I'm assuming this is not possible under windows even in version 5.0.1 of php and I'm going to try again under cygwin.

If there is anything I can do to help code this bug/ability out.  Let me know.  I know C/C++ and assembly but I am not familiar with the PHP source code..

Thank you.
 [2004-09-20 17:29 UTC] wez@php.net
win32 console doesn't work the same way as a unix tty, so if this works, I'll be really surprised.  The official line is that we're not changing anything to make it happen at this time.

Secondly, you should be using the constant STDIN instead of fopen('php://stdin') in PHP 5 and later.
 [2004-09-21 04:20 UTC] xxmettedraqxx at comcast dot net
Well from what I've read now.  This can only be done under Unix for CLI..
I know php was not designed to be a web server language but it certainly seems to be leaning in the direction of becoming a great way to make something using sockets to serve just about anything.  Possibly even home made transfer protocols.  That would be cool.

But as far as the STDIN, which I tried using a few times and I figured the code below was more drawn out..

Now I'm trying to see if I can fake this out using socket streams and the local connection to itself.. possibly even using stdin through a socket create.  I'm not sure yet.. still coding it out and testing a few things.. and if I can find a way to help you guys (I can't navigate web sites very well).  I would code some c/c++ for the windows end of things.  I would love for this to be portable across windows also.

Thank you for your comment, I appreciate the help in any way, shape or form that I can get it.

once again, thank you.

Mettedraq.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC