skyprog Posted May 12, 2014 Share Posted May 12, 2014 I am executing two child process using proc open in PHP. After both the process are created I access the stdout of first process but it gives error that the descriptor is not valid, where as the output of second process is displayed. It seems that the pipes that were attached with stdout of first process are no more connected with it and instead they are pointing to second process. How can I have correct display of both the processes? PHP Code <?php echo "Executing a process\n"; $cwd = '/var/www/html/test-9-5-14'; $exe_command = ('/var/www/html/test-9-5-14/./hello'); $descriptorspec = array( 0 => array("pipe", "r"), // stdin -> for execution 1 => array("pipe", "w"), // stdout -> for execution 2 => array("pipe", "w") // stderr ); $process = proc_open($exe_command, $descriptorspec, $pipes, $cwd);//creating child process stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[0], 0); stream_set_blocking($pipes[2], 0); sleep(1); if (is_resource($process)) { echo "Process Created"; $stdout1 = array($pipes[1]);//save stdout in a variable defined above print_r ($stdout1); } $exe_command = ('/var/www/html/test-9-5-14/./add'); $descriptorspec = array( 0 => array("pipe", "r"), // stdin -> for execution 1 => array("pipe", "w"), // stdout -> for execution 2 => array("pipe", "w") // stderr ); $process = proc_open($exe_command, $descriptorspec, $pipes1, $cwd);//creating child process stream_set_blocking($pipes1[1], 0); stream_set_blocking($pipes1[0], 0); stream_set_blocking($pipes1[2], 0); sleep(1); if (is_resource($process)) { echo "Process 2 Created"; $stdout2 = array($pipes1[1]);//save stdout in a variable defined above print_r ($stdout2); } $s = fgets($stdout1[0]); echo $s; $s = fgets($stdout2[0]); echo $s; ?> Output Executing a process Process CreatedArray ( [0] => Resource id #5 ) Process 2 CreatedArray ( [0] => Resource id #9 ) PHP Warning: fgets(): 5 is not a valid stream resource in /var/www/html/test-9-5-14/test.php on line 70 --Enter two integers > --Enter two integers > is the output of my second process whereas the first process stdout descriptor 5 is invalid.Any ideas please. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.