php - multiple stream select with proc_open receive responses from slow process -


i'm calling slow python script child process (echonest remix code) wp plugin using proc_open , variation on code found here @ this question.

the (python) script takes minute process (a bunch of audio), , i'm hoping find way display output browser printed python script. stands, output of entire function not display until proc_open , stream_select processes end. includes echo statement @ start of function.

<?php echo "why wait before printing me out?";  $description = array (          0 => array("pipe", "r"),  // stdin     1 => array("pipe", "w"),  // stdout     2 => array("pipe", "w")   // stderr );  $application_system = "python "; $application_name .= "glitcher/glitchmix.py"; $application = $application_system.$application_name.$separator;  $argv1 = 'a variable'; $argv2 = 'another variable'; $separator = " ";  $pipes = array();  $proc = proc_open ( $application.$separator.$argv1.$separator.$argv2, $description , $pipes, glitch_player_dir);  // set streams non blockin mode stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0);  // pid via get_status call $status = proc_get_status($proc); // status check here if($status === false)  $pid = $status['pid']; // now, poll childs termination while(true) {     // detect if child has terminated - php way     $status = proc_get_status($proc);     //  retval checks : ($status === false) , ($status['running'] === false)      // read childs stdout , stderr     // avoid *forever* blocking through using time out (1sec)     foreach(array(1, 2) $desc) {         // check stdout data         $read = array($pipes[$desc]);         $write = null;         $except = null;         $tv = 1;         $n = stream_select($read, $write, $except, $tv);         if($n > 0) {             {                 $data = fgets($pipes[$desc], 8092);                 echo $data . "\n<br/>";             } while (strlen($data) > 0);         }     } } ?> 

is possible use multiple calls stream_select echo child process output comes?

obviously i'm new socket programming , forward more insight s.o. community.

it's funny , simple reason. see -u option python. waste 2 days on same 1 problem. when substitute python bash , test output bash script - receive it.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -