Skip to content

Instantly share code, notes, and snippets.

@mllvzeth
Created March 29, 2017 21:06
Show Gist options
  • Save mllvzeth/6e9a3f44461edb337f932ae98ee41bb5 to your computer and use it in GitHub Desktop.
Save mllvzeth/6e9a3f44461edb337f932ae98ee41bb5 to your computer and use it in GitHub Desktop.
Runinng process with realtime output in PHP
//*
* 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