|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65879 stream_select on STDIN returns 1 even on blocking stream
Submitted: 2013-10-10 23:54 UTC Modified: 2020-09-08 09:42 UTC
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: marco at m-s-d dot eu Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 5.5.4 OS: Windows 7 x64
Private report: No CVE-ID: None
 [2013-10-10 23:54 UTC] marco at m-s-d dot eu
When doing a stream_select(STDIN,null,null,0), then the return value will be 1 as soon as one switches the window focus or presses a meta key, but a subsequent fread(STDIN) will block.

This is possible the same problem as #42044, which was closed as not a bug - however, I deem this behaviour as a bug as the select() is supposed to make sure a fread() will NOT block!

Test script:
public static function sleep($secs) {
		echo "sleeping $secs s";
		for($i=0;$i<$secs;$i++) {
			if($num>0) { //read and discard
			echo "fd '$num'\n";
				echo "'".fread(STDIN,4096)."'";
			echo "\r".str_repeat(" ",60)."\r";
			echo date("d.m.Y H:i:s") . " still sleeping for ".($secs-$i)." seconds";
		echo "done sleeping\n";

Expected result:
The sleep counter is supposed to keep on counting in the background even if the commandline window is not focused.

Actual result:
The display will be e.g. "sleeping 20 sfd '1'" after focusing away.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-08 08:46 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-09-08 08:46 UTC]
The problem is that console input signals as soon as
ReadConsoleInput() would not block (i.e. there is at least one
console input record available), but ReadFile() blocks until a
line of input is available (assuming the default of line buffered
input).  I don't see a way to reasonably cater to this, so I'm
changing to documenation issue.
 [2020-09-08 09:42 UTC]
-Status: Verified +Status: Closed
 [2020-09-08 09:42 UTC]
Automatic comment on behalf of cmb
Log: Fix #65879: stream_select on STDIN returns 1 even on blocking stream
 [2020-09-08 11:50 UTC]
Automatic comment on behalf of mumumu
Log: Fix #65879: stream_select on STDIN returns 1 even on blocking stream Remove out-dated info regarding Windows 98 Fix #55528: Values for the &quot;whence&quot; parameter of the &quot;stream_seek&quot;
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 02:01:25 2020 UTC