Doc #65879 [Ver->Csd]: stream_select on STDIN returns 1 even on blocking stream

From: Date: Tue, 08 Sep 2020 09:42:03 +0000
Subject: Doc #65879 [Ver->Csd]: stream_select on STDIN returns 1 even on blocking stream
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17876@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65879&edit=1

 ID:                 65879
 Updated by:         cmb@php.net
 Reported by:        marco at m-s-d dot eu
 Summary:            stream_select on STDIN returns 1 even on blocking
                     stream
-Status:             Verified
+Status:             Closed
 Type:               Documentation Problem
 Package:            Streams related
 Operating System:   Windows 7 x64
 PHP Version:        5.5.4
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Fixed with <http://svn.php.net/viewvc?view=revision&revision=350535>.


Previous Comments:
------------------------------------------------------------------------
[2020-09-08 08:46:55] 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.

------------------------------------------------------------------------
[2013-10-10 23:54:51] 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.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=65879&edit=1


Thread (2 messages)

« previous php.doc.bugs (#17876) next »