Bug #34972 [Opn]: STDIN should allow nonblocking
| From: | cmb@php.net | Date: | Wed, 01 Jul 2020 14:30:03 +0000 |
| Subject: | Bug #34972 [Opn]: STDIN should allow nonblocking | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227764@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=34972&edit=1
ID: 34972
Updated by: cmb@php.net
Reported by: VJTD3 at VJTD3 dot com
-Summary: STDIN won't allow nonblocking.
+Summary: STDIN should allow nonblocking
Status: Open
Type: Bug
Package: Streams related
Operating System: win32 only
PHP Version: 5.2CVS-2008-07-15
Block user comment: N
Private report: N
New Comment:
Making stdio streams non-blocking is not (yet) supported on
Windows[1]; that is not a bug, though.
To implement it, one would have to implement asynchronous I/O[2]
on Windows. A pull request would be welcome.
Also note that there is an open pull request for socket support
for proc_open()[3], which could be used as partial workaround for
this issue.
[1] <https://github.com/php/php-src/blob/php-7.4.7/main/streams/plain_wrapper.c#L662>
[2] <https://docs.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o>
[3] <https://github.com/php/php-src/pull/5777>
Previous Comments:
------------------------------------------------------------------------
[2019-06-01 00:51:49] lstubbs at techno dot express
I'm using two windows systems:
Windows 10 using PHP 7.2.16 (cli) (built: Mar 6 2019 21:52:05) ( NTS MSVC15 (Visual C++ 2017) x64 )
Windows 7 using PHP 7.1.16 (cli) (built: Mar 28 2018 21:15:31) ( ZTS MSVC14 (Visual C++ 2015) x64 )
The ZTS builds blocks ONCE an key is press, otherwise non-blocking works.
The NTS builds blocks regardless an key is press or not, always blocking.
I know have PHP 7.2 ZTS builds on both systems, and STDIN non-blocking works until, i press an key,
then blocks waiting for me to hit enter.
see https://github.com/symplely/coroutine/blob/master/examples/asyncWaitFor.php
It basically will run other routines until the user hits enter.
On Linux numbers will scroll across until enter is press, pressing any key does not stop the other
routine running, the routine actually produces the number printout.
On Windows will scroll the same, but stop on any key being pressed, the routines will pause waiting
for enter key.
------------------------------------------------------------------------
[2017-04-15 07:50:32] procman at interia dot pl
I have the same issue on Windows 7 (64) and PHP 7.0.13
There is no way to read from STDIN in non-blocking mode regardless of whether I run script in cmd or
mingw32. I have tried every single solution I found, and finally hit here. Very sad because it is
impossible to write simple, portable application in PHP.
This bug has 12 years, so please tell us whether it is at all possible to fix, or not (for example
if it is matter of OS, not PHP internals).
------------------------------------------------------------------------
[2017-01-18 20:33:44] stahlstift at gmail dot com
I want to let a CLI script running until the user inputs "Enter" or CTRL+C. On *nix
systems thats not a real problem because I can read async from STDIN or better use PCNTL to listen
for SIGINT (CTRL+C).
On Windows there is now no solution... CTRL+C will kill the script like "kill -9" on *nix
- so there is no shutdown handler called. A fallback solution could be reading non blocking from
STDIN and wait for input but thats currently not possible.
------------------------------------------------------------------------
[2016-04-19 15:27:45] jan dot bouvrie at gmail dot com
Ignore my last comment, posted with the wrong bug. Dupes can be confusing. :)
------------------------------------------------------------------------
[2016-04-19 15:24:33] jan dot bouvrie at gmail dot com
I'm also in the parallel processes boat, still no movement on this? Tested it again on 5.6.20,
but no luck.
Perhaps related, my code running on Windows uses stream_select() on proc_open() file descriptors,
even though the manual states: "Use of stream_select() on file descriptors returned by
proc_open() will fail and return FALSE under Windows."
For kicks I tested the same code on Windows/PHP 7.0.5, and indeed the stream_select() returns FALSE
there, just like the manual states.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=34972
--
Edit this bug report at https://bugs.php.net/bug.php?id=34972&edit=1