php.net |  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
Votes:2
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
Description:
------------
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++) {
			$a=array(STDIN);
			$b=NULL;
			$num=stream_select($a,$b,$b,0);
			if($num>0) { //read and discard
			echo "fd '$num'\n";
				echo "'".fread(STDIN,4096)."'";
				break;
			}
			echo "\r".str_repeat(" ",60)."\r";
			echo date("d.m.Y H:i:s") . " still sleeping for ".($secs-$i)." seconds";
			sleep(1);	
		}
		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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-08 08:46 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2020-09-08 08:46 UTC] cmb@php.net
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] cmb@php.net
-Status: Verified +Status: Closed
 [2020-09-08 09:42 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=28abaa892f7056bd4736fd73069f6188832189b4
Log: Fix #65879: stream_select on STDIN returns 1 even on blocking stream
 [2020-09-08 11:50 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=6dcb02d8b1fcb6e98f61f48a52903419afcc2c69
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