ID:               34972
 Comment by:       frase at cs dot wisc dot edu
 Reported By:      VJTD3 at VJTD3 dot com
 Status:           Assigned
 Bug Type:         Streams related
 Operating System: win32 only
 PHP Version:      5.2CVS-2008-07-15
 Assigned To:      pajoye
 New Comment:

I'm having the same trouble.

With php-5.3.0-beta1 on Linux it works fine, both on STDIN and on
fopen('/dev/ttyS0').  stream_set_blocking() returns true,
stream_get_meta_data() confirms, and the stream behaves as if
non-blocking.

But with php-5.2.9 on Windows 2000 it doesn't work for either STDIN or
the serial port (COM1 instead of /dev/ttyS0).  stream_set_blocking()
returns false, stream_get_meta_data() shows blocking, and the streams do
in fact block.  I also tried stream_set_timeout() with a tiny value, to
simulate the effect, but that also returns false and doesn't work.


Previous Comments:
------------------------------------------------------------------------

[2008-10-24 16:11:54] [email protected]

Assigned to the windows port maintainer.

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

[2008-03-15 10:57:09] VJTD3 at VJTD3 dot com

on *nix it seems to be solved.

easy way to test:
php -r "stream_set_blocking(STDIN, FALSE);echo fread(STDIN, 10);"

on *nix it instantly exits. (correct behavior)
on windows it will hang for input. (incorrect behavior, it's ignoring
the non blocking setting.)

tested on 5.2.5

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

[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.

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

[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

Reply via email to