#35131 [NEW]: stream_select() in conjuntion with popen() does not appear to work

From: Date: Sun, 06 Nov 2005 21:07:20 +0000
Subject: #35131 [NEW]: stream_select() in conjuntion with popen() does not appear to work
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87701@lists.php.net to get a copy of this message
From: larryjadams at comcast dot net Operating system: WindowsXP Pro SP2 PHP version: 5.0.5 PHP Bug Type: Scripting Engine problem Bug description: stream_select() in conjuntion with popen() does not appear to work Description: ------------ If I call $my_fd = popen("mycommand", "rb"); to a function that hangs/suspends and then subsquently call: stream_select(...) using $read=array($my_fd) with a timeout, the steam_select returns immediately, event if I have set $my_fd as blocking using stream_set_blocking(); I would like stream_select to wait on output from the pipe prior to firing, or to drive a timeout. Thanks, Larry Adams The Cacti Group Reproduce code: --------------- if (function_exists("stream_select")) { if ($config["cacti_server_os"] == "unix") { $fp = popen($command, "r"); }else{ $fp = popen($command, "rb"); } /* set script server timeout */ $script_timeout = read_config_option("script_timeout"); /* establish timeout variables */ $to_sec = floor($script_timeout/1000); $to_usec = ($script_timeout%1000)*1000; /* Prepare the read array */ $read = array($fp); stream_set_blocking ($fp, 1); if (false === ($num_changed_streams = stream_select($read, $write = NULL, $except = NULL, $to_sec, $to_usec))) { cacti_log("WARNING: SERVER POPEN Timed out."); $output = "U"; }elseif ($num_changed_streams > 0) { $output = fgets($fp, 4096); } pclose($fp); }else{ $output = $command; } $command = a file with the following: <?php sleep(20); echo "Hello:20.00\n"; ?> The stream_select timeout is 5 seconds. Expected result: ---------------- popen will be called, stream_select will block until timeout has expired, the number of fd's changed will be 0 and my result will be as expected. Actual result: -------------- stream_select returns immediately. -- Edit bug report at http://bugs.php.net/?id=35131&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35131&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35131&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35131&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35131&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35131&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35131&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35131&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35131&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35131&r=support Expected behavior: http://bugs.php.net/fix.php?id=35131&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35131&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35131&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35131&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35131&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35131&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35131&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35131&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35131&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35131&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35131&r=mysqlcfg

« previous php.bugs (#87701) next »