Re: Echo from stream_select as output is generated by child process?
| From: | Aziz Saleh | Date: | Thu, 05 Jun 2014 22:25:18 +0000 |
| Subject: | Re: Echo from stream_select as output is generated by child process? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323392@lists.php.net to get a copy of this message | ||
On Thu, Jun 5, 2014 at 6:18 PM, Mike Kilmer <mike@madhappy.com> wrote:
> Hi all. This is my first post here.
>
> I'm using proc_open to call a python script.
>
> The (python) child process takes about a minute to run, and when run from
> the command line it prints results as they are completed.
>
> With the php script, it just prints them all when it's complete.
>
> Is there a way to return the python output to the browser in real time?
>
> Possibly using more than one stream_select with varying time_outs?
>
> The full script is posted on StackOverflow, and what I think are the
> relevant segments are below:
>
> $proc = proc_open ( $child_process , $description , $pipes,
> glitch_player_DIR, $env );
>
> // set all streams to non blockin mode
> stream_set_blocking($pipes[1], 0);
> stream_set_blocking($pipes[2], 0);
>
> foreach(array(1, 2) as $desc) {
> // check stdout for data
> $read = array($pipes[$desc]);
> $write = NULL;
> $except = NULL;
> $tv = 0;
> $utv = 50000;
>
> $n = stream_select($read, $write, $except, $tv, $utv);
> if($n > 0) {
> do {
> $data = fread($pipes[$desc], 8092);
> if (is_string($data) && ($data != ""))
> echo $data ."<br/>";
> array_push($glitch_response, $data);
> } while (strlen($data) > 0);
> }
> }
>
> Thanks for your feedback.
>
> Mike Kilmer
> mZoo.org
What do you have for your descriptor array (second param on proc_open)?