Bug #69049 [Opn->Fbk]: Unable to get output of slow process
| From: | ab@php.net | Date: | Fri, 13 Feb 2015 09:06:15 +0000 |
| Subject: | Bug #69049 [Opn->Fbk]: Unable to get output of slow process | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190650@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69049&edit=1
ID: 69049
Updated by: ab@php.net
Reported by: aserbulov at parallels dot com
Summary: Unable to get output of slow process
-Status: Open
+Status: Feedback
Type: Bug
Package: Streams related
Operating System: Windows
PHP Version: 5.5.21
Block user comment: N
Private report: N
New Comment:
Hi,
thanks for the report. Just removing that part doesn't seem to be a correct solution. Please
reread the tickets you've linked for why it was done so.
With the particular issue, you can still implement it with a slow process. I'd suggest to not
to close strerr but read from it simultaneously. You expect a keyword 'done' from the
stdout, but that doesn't prevent you to read some kind of keep-alive stuff from stderr. You
might also look up some example in the tests appended with the bug #51800.
Of course it's bad when not having control over process.php . I was thinking about introducing
a userspace function to peek on the pipe content. Another possibility were to introduce one more
option to proc_open which would set the expected timeout. But none of that is yet done, lets see
whether it's needed at all.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-02-13 05:44:25] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69049&edit=1