php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42044 stream_select
Submitted: 2007-07-19 09:04 UTC Modified: 2007-07-19 09:39 UTC
From: zeusgerde at arcor dot de Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2.3 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zeusgerde at arcor dot de
New email:
PHP Version: OS:

 

 [2007-07-19 09:04 UTC] zeusgerde at arcor dot de
Description:
------------
I try to read from STDIN in the windows console (cmd.exe).

With the code below I get as expected "0" several times until I start typing.
But when I start typing (not hitting enter) I get "3", all arrays contain STDIN, STDERR and STDOUT and fread() blocks (of course).
The same happens if I focus on another window with the mouse cursor.

Reproduce code:
---------------
while (1) {
  $aException = $aWrite = $aRead = Array(STDIN, STDERR, STDOUT);
  $iChangedStreams = @stream_select($aRead, $aWrite, $aException, 1, 0);
  echo $iChangedStreams;

  if ($iChangedStreams) {
    if (in_array(STDIN, $aRead, true)) {
      $strBuffer = fread(STDIN, 1);
    }
  }
}


Expected result:
----------------
$aRead == Array(STDIN);
$aWrite == Array(STDIN, STDOUT, STDERR);
$aException == Array();

/* not sure about STDIN in $aWrite */

Actual result:
--------------
$aRead == Array(STDIN, STDOUT, STDERR);
$aWrite == Array(STDIN, STDOUT, STDERR);
$aException == Array(STDIN, STDOUT, STDERR);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-19 09:23 UTC] jani@php.net
Remove the @ in front of stream_select() and you'll know why your code does not work. Also read the manual page for stream_select again:
http://www.php.net/stream_select
 [2007-07-19 09:39 UTC] zeusgerde at arcor dot de
Removed the @
Added error_reporting(E_ALL);
display_errors is on

Result: the same as mentioned in first post

> Also read the manual page for stream_select again

I did but did not find anything matching my problem.

http://php.net/stream_select says:
| Note: When stream_select() returns, the arrays read, write and
| except are modified to indicate which stream resource(s) actually
| changed status.

Seems not to change anything.

http://php.net/stream_select says:
| On error FALSE  is returned and a warning raised (this can happen if
| the system call is interrupted by an incoming signal).

FALSE is not returned. No warning raised.

http://php.net/stream_select says:
| Note:  If you read/write to a stream returned in the arrays be aware
| that they do not necessarily read/write the full amount of data you
| have requested. Be prepared to even only be able to read/write a
| single byte.

I can not read a single byte.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 04:01:26 2024 UTC