3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to ); $cwd = '/tmp'; $env = array('some_option' => 'aeiou'); $process = proc_open('php', $descriptorspec, $pipes, $cwd, $env); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], '<?php print_r($_ENV); ?>'); fclose($pipes[0]); echo stream_get_contents($pipes[1]); fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); echo "command returned $return_value\n"; } ?>
Output for 5.6.28, 7.0.14 - 7.1.0
command returned 127
Output for 5.0.0 - 5.6.25, 7.0.0 - 7.0.10
Warning: proc_open(): fork failed - Resource temporarily unavailable in /in/LTmj9 on line 11
Output for 4.3.0 - 4.4.9
Warning: proc_open() expects exactly 3 parameters, 5 given in /in/LTmj9 on line 11