php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44908 stream_select on pipes returned by proc_open returns streams that are not ready
Submitted: 2008-05-04 08:06 UTC Modified: 2014-09-29 14:49 UTC
Votes:12
Avg. Score:4.4 ± 0.9
Reproduced:12 of 12 (100.0%)
Same Version:5 (41.7%)
Same OS:7 (58.3%)
From: mike at silverorange dot com Assigned:
Status: Wont fix Package: Streams related
PHP Version: 5.2CVS-2008-09-08 OS: *
Private report: No CVE-ID: None
 [2008-05-04 08:06 UTC] mike at silverorange dot com
Description:
------------
When using stream_select() on pipes returned by proc_open() in Windows, input streams that are not ready are returned in the modified $read array.

Reproduce code:
---------------
<?php

$pipes = array();
$proc = proc_open('c:/progra~1/gnu/gnupg/gpg.exe', array(
     0 => array('pipe', 'r'),
     1 => array('pipe', 'w'),
     2 => array('pipe', 'w')), $pipes, null, $_ENV);

if ($proc !== false) {
    $write  = array($pipes[0]);
    $read   = array($pipes[1], $pipes[2]);
    $except = null;

    $changed = stream_select($read, $write, $except, null);

    if ($changed) {
      print_r($read);
      print_r($write);
    }

    proc_close($proc);
}

?>

Expected result:
----------------
The read array will be empty and the write array will contain stdin.

Actual result:
--------------
The read array contains stdin and the write array contains stdout and stderr. The stdout and stderr streams have no data ready and fread() will block indefinitely.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-04 08:08 UTC] mike at silverorange dot com
Edit:

Actual result:
--------------
The _write_ array contains stdin and the _read_ array contains stdout and stderr. The stdout and stderr streams have no data ready and fread() will block indefinitely.
 [2008-05-04 21:50 UTC] jani@php.net
Please check the used PHP version. (phpinfo(); usually is the best way)
 [2008-05-04 23:31 UTC] mike at silverorange dot com
Jani,

I'm using the MSI install of PHP 5.2.6 (cli) (built Apr 30 2008 16:19:00) on Windows XP Home with Service Pack 2.
 [2008-05-27 15:46 UTC] pciocan at gmail dot com
I encountered the same problem with stream_select but when using named pipes (created with posix_mkfifo and opened using fopen). Is there a workaround for this problem?

Thank you,
Pavel
 [2008-05-27 15:51 UTC] ciocan at gmail dot com
Sorry i forgot to mention that for me it happens in Linux: CentOS 5, php 5.2.6 (and also tried on CentoOS 5, php 5.2.1)

Thank you,
Pavel
 [2008-09-08 14:51 UTC] gauthierm@php.net
Jani,

I tried the posted development snapshot and the test still fails. The stream_select() call still returns stdout and stderr streams  in the read array and reading from either will block indefinitely (because they're not ready).

Please reopen this bug.
 [2008-11-25 03:57 UTC] lbarnaud@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-12-03 01:00 UTC] 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".
 [2009-02-07 11:01 UTC] ondraster at gmail dot com
function loadModule ( $moduleName ) {
 $descriptorspec = array(
  0 => array("pipe", "r"),
  1 => array("pipe", "w"),
  2 => array("file", "errors.txt", "a")
 );
 $module = proc_open ( 'I:\httpd\php\php.exe I:\httpd\php-irc-bot\module.' . $moduleName . '.php', $descriptorspec, $pipes, NULL, array ( 'RUNFIRST' => true ) );
 $this -> runningModules[$moduleName] = $module;
 echo "Registered new module: $moduleName\r\n";
 $this -> pipes[$moduleName] = $pipes;		
} 

... few code ...

foreach ( $this -> pipes as $module => $pipes ) {				
 fwrite ( $pipes[0], $msg );					
 $forChange[] = $pipes[1];					
}
$r = NULL;
$e = NULL;
$sock_change = stream_select ( $forChange, $r, $e, 0, 20 );				
if ( $sock_change > 0 && $sock_change !== false ) {				
foreach ( $forChange as $key => $stream ) {			
 echo fread ( $stream, 4096 );	
 }	
}

PHP 5.2.2, 5.2.8, 5.3 (Windows Vista 64bit, x86 build, running from CLI) still not working. After 3/4 of year still not fixed. PHP6 says some warnings, never seen before ("Cannot cast a filtered stream on this system", complete errors: http://clip2net.com/clip/m12051/1233956312-clip-16kb.png
 [2014-09-29 14:49 UTC] ab@php.net
-Status: No Feedback +Status: Wont fix
 [2014-09-29 14:49 UTC] ab@php.net
see bug #47918
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC