|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-02-13 05:44 UTC] aserbulov at parallels dot com
Description: ------------ If you use proc_open to open slow process (it should write to stdout not immediately, but after some time), you never get process output. Slow process emulation: --- <?php sleep(60); // Do some work fwrite(STDOUT, 'done'); exit(0); --- It is side effect of bug https://bugs.php.net/bug.php?id=51800 fix. Test script: --------------- $cmd = "\"C:/Program Files/php/php.exe\" process.php"; $status; $stdout = ""; $pipes = []; $descriptors = [ 0 => ["pipe", "r"], // stdin 1 => ["pipe", "w"], // stdout 2 => ["pipe", "w"], // stderr ]; $process = proc_open($cmd, $descriptors, $pipes); fclose($pipes[0]); fclose($pipes[2]); while (!feof($pipes[1])) $stdout .= fread($pipes[1], 1024); fclose($pipes[1]); $status = proc_close($process); print_r(["status" => $status, "stdout" => $stdout]); Expected result: ---------------- 1. fread() function should read the pipe until the desired number of bytes has been read or reaches the end of the pipe. 2. feof() function should return true if fread() function reaches the end of the pipe. Actual result: -------------- 1. fread() return empty string 2. feof($pipes[1]) return true after ~36 seconds. Patchesstream_oef.diff (last revision 2015-02-13 12:39 UTC by aserbulov at parallels dot com)plain_wrapper.c.diff (last revision 2015-02-13 05:45 UTC by aserbulov at parallels dot com) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 00:00:01 2025 UTC |
while (!feof($pipes[1]) || !feof($pipes[2])) { $stdout .= fread($pipes[1], 1024); // wait ~32 seconds, set eof and return empty string $stderr .= fread($pipes[2], 1024); // wait ~28 seconds, set eof and return empty string }I mean doing it like this process.php <?php sleep(30); // Do some work fwrite(STDERR, "alive"); sleep(30); // Do some work fwrite(STDOUT, 'done'); exit(0); ?> test.php <?php $cmd = "\"" . PHP_BINARY . "\" " . dirname(__FILE__) . "/process.php"; $status; $stdout = ""; $stderr = ""; $pipes = []; $descriptors = [ 0 => ["pipe", "r"], // stdin 1 => ["pipe", "w"], // stdout 2 => ["pipe", "w"], // stderr ]; $process = proc_open($cmd, $descriptors, $pipes); fclose($pipes[0]); while (!feof($pipes[1]) || !feof($pipes[2])) { $stdout .= fread($pipes[1], 1024); $stderr .= fread($pipes[2], 1024); /* throw away */ } fclose($pipes[1]); fclose($pipes[2]); $status = proc_close($process); print_r(["status" => $status, "stdout" => $stdout]);