#34972 [Com]: STDIN won't allow nonblocking.
| From: | julian at precisium dot com dot au | Date: | Thu, 23 Aug 2007 15:53:20 +0000 |
| Subject: | #34972 [Com]: STDIN won't allow nonblocking. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116561@lists.php.net to get a copy of this message | ||
ID: 34972
Comment by: julian at precisium dot com dot au
Reported By: VJTD3 at VJTD3 dot com
Status: Open
Bug Type: Streams related
Operating System: *
PHP Version: php5.1-200603270630
Assigned To: wez
New Comment:
I'm having this problem on Vista x64 with PHP 5.2.3.
This is a real showstopper for certain types of CLI app - people can't
always be waiting for newlines or eofs to read their data.
I don't mean to be rude but I'm kinda shocked such a major bug has been
unaddressed for nearly 2 years. I guess it just means people aren't
really using PHP for CLI apps on the windows platform.
Previous Comments:
------------------------------------------------------------------------
[2007-08-19 20:51:34] donnyk at gmail dot com
i also have the same problem, i've tried the latest snapshot on windows
to no avail. It works on my linux systems however.
------------------------------------------------------------------------
[2007-08-10 13:01:48] VJTD3 at VJTD3 dot com
<?php
stream_set_blocking(STDIN, FALSE);
echo fread(STDIN, 10);
?>
notice how it just sits there? (blocking) it should exit instantly with
a null echo. (same as a tcp connection where if you just do a read that
is too fast with nonblocking it never gets a chance to fetch the data.)
what is happening is that php is blocking waiting for input
(specifically enter (line ending))
problem:
if you are echoing debug information and want to use key functionality
in tandem you can't because everything is blocked till you hit enter.
------------------------------------------------------------------------
[2007-07-25 01:00:00] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2007-07-17 14:28:03] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows (zip):
http://snaps.php.net/win32/php5.2-win32-latest.zip
For Windows (installer):
http://snaps.php.net/win32/php5.2-win32-installer-latest.msi
I can't reproduce this (or very likely didn't understand the problem :)
------------------------------------------------------------------------
[2006-03-27 14:12:28] VJTD3 at VJTD3 dot com
error in last message, "stream_select()" was ment.
code using "stream_select()" that still blocks:
<?php
set_time_limit('0');
# note for php4 or lower STDIN isn't a defined "constant".
if (version_compare(phpversion(), '5.0.0', '<')) {
define('STDIN', fopen('php://stdin', 'r'));
}
for ($i=1;$i<11;$i++) {
unset($read);
$read[] = STDIN;
stream_select($read, $write = null, $except = null, $tv = 0);
if (count($read)) {
$data4 = @fread(STDIN, 1500);
$data4 = str_replace("\r\n", "\n", $data4);
$data4 = str_replace("\n\r", "\n", $data4);
$data4 = str_replace("\r", "\n", $data4);
$data4 = str_replace("\n", '', $data4);
}
echo 'pass: '.$i.' -> data: '.(strlen(@$data4) ? $data4 :
'empty')."\n";
unset($data4);
sleep('1');
}
?>
the second you type/click a arrow key/anything it goes into blocking
mode again.
------------------------------------------------------------------------
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
http://bugs.php.net/34972
--
Edit this bug report at http://bugs.php.net/?id=34972&edit=1