Created
March 29, 2017 21:06
-
-
Save mllvzeth/6e9a3f44461edb337f932ae98ee41bb5 to your computer and use it in GitHub Desktop.
Runinng process with realtime output in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* | |
* http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php | |
* | |
// | |
$cmd = "ping 127.0.0.1"; | |
$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("pipe", "w") // stderr is a pipe that the child will write to | |
); | |
flush(); | |
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array()); | |
echo "<pre>"; | |
if (is_resource($process)) { | |
while ($s = fgets($pipes[1])) { | |
print $s; | |
flush(); | |
} | |
} | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment