function rtprocess
($commands = array()){ ini_set('zlib.output_compression', 0);
$pipes = [];
$processes = [];
$output = [];
foreach($commands as $key => $command){
$descriptorspec[$key] = array( );
$processes[] = proc_open($command, $descriptorspec[$key], $procPipes); $pipes[$key] = $procPipes;
$output[$key] = '';
}
echo '<pre>';
do{
$allFinished = true;
foreach($processes as $key => $process){
if($returnedValues['running']){
$allFinished = false;
$s = fread($pipes[$key][1],1024); if($s){
$output[$key] .= $s;
print($s);
}
}
}
} while($allFinished == false);
echo '</pre>';
foreach($processes as $process){
}
foreach($output as $o){
echo '<pre>'.print_r($o,true).'</pre>'; }
}
$commands[] = "ping -n 5 127.0.0.1 2>&1";
$commands[] = "ping -n 5 10.0.0.1 2>&1";
//rtprocess($commands);
ZnVuY3Rpb24gcnRwcm9jZXNzKCRjb21tYW5kcyA9IGFycmF5KCkpewogICAgaW5pX3NldCgnemxpYi5vdXRwdXRfY29tcHJlc3Npb24nLCAwKTsKICAgIGluaV9zZXQoJ2ltcGxpY2l0X2ZsdXNoJywgMSk7CiAgICBvYl9pbXBsaWNpdF9mbHVzaCgxKTsKICAgIAogICAgJHBpcGVzID0gW107CiAgICAkcHJvY2Vzc2VzID0gW107CiAgICAkb3V0cHV0ID0gW107CiAgICBmb3JlYWNoKCRjb21tYW5kcyBhcyAka2V5ID0+ICRjb21tYW5kKXsKICAgICAgICAkZGVzY3JpcHRvcnNwZWNbJGtleV0gPSBhcnJheSgKICAgICAgICAgICAgMCA9PiBhcnJheSgncGlwZScsICdyJyksCiAgICAgICAgICAgIDEgPT4gYXJyYXkoJ3BpcGUnLCAndycpLAogICAgICAgICAgICAyID0+IGFycmF5KCdwaXBlJywgJ3cnKQogICAgICAgICk7CiAgICAgICAgJHByb2Nlc3Nlc1tdID0gcHJvY19vcGVuKCRjb21tYW5kLCAkZGVzY3JpcHRvcnNwZWNbJGtleV0sICRwcm9jUGlwZXMpOwogICAgICAgIHN0cmVhbV9zZXRfYmxvY2tpbmcoJHByb2NQaXBlc1sxXSwgMCk7CiAgICAgICAgJHBpcGVzWyRrZXldID0gJHByb2NQaXBlczsKICAgICAgICAkb3V0cHV0WyRrZXldID0gJyc7CiAgICB9CiAgICAKICAgIGVjaG8gJzxwcmU+JzsKICAgIGRvewogICAgICAgICRhbGxGaW5pc2hlZCA9IHRydWU7CiAgICAgICAgZm9yZWFjaCgkcHJvY2Vzc2VzIGFzICRrZXkgPT4gJHByb2Nlc3MpewogICAgICAgICAgICAkcmV0dXJuZWRWYWx1ZXMgPSBwcm9jX2dldF9zdGF0dXMoJHByb2Nlc3MpOwogICAgICAgICAgICBpZigkcmV0dXJuZWRWYWx1ZXNbJ3J1bm5pbmcnXSl7CiAgICAgICAgICAgICAgICAkYWxsRmluaXNoZWQgPSBmYWxzZTsKICAgICAgICAgICAgICAgICRzID0gZnJlYWQoJHBpcGVzWyRrZXldWzFdLDEwMjQpOwogICAgICAgICAgICAgICAgaWYoJHMpewogICAgICAgICAgICAgICAgICAgICRvdXRwdXRbJGtleV0gLj0gJHM7CiAgICAgICAgICAgICAgICAgICAgcHJpbnQoJHMpOwogICAgICAgICAgICAgICAgICAgIG9iX2ZsdXNoKCk7CiAgICAgICAgICAgICAgICAgICAgZmx1c2goKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSB3aGlsZSgkYWxsRmluaXNoZWQgPT0gZmFsc2UpOwogICAgZWNobyAnPC9wcmU+JzsKICAgIAogICAgZm9yZWFjaCgkcHJvY2Vzc2VzIGFzICRwcm9jZXNzKXsKICAgICAgICBwcm9jX2Nsb3NlKCRwcm9jZXNzKTsKICAgIH0KICAgIAogICAgZm9yZWFjaCgkb3V0cHV0IGFzICRvKXsKICAgICAgICBlY2hvICc8cHJlPicucHJpbnRfcigkbyx0cnVlKS4nPC9wcmU+JzsKICAgIH0KfQoKJGNvbW1hbmRzID0gYXJyYXkoKTsKJGNvbW1hbmRzW10gPSAicGluZyAtbiA1IDEyNy4wLjAuMSAyPiYxIjsKJGNvbW1hbmRzW10gPSAicGluZyAtbiA1IDEwLjAuMC4xIDI+JjEiOwovL3J0cHJvY2VzcygkY29tbWFuZHMpOw==
function rtprocess($commands = array()){
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
ob_implicit_flush(1);
$pipes = [];
$processes = [];
$output = [];
foreach($commands as $key => $command){
$descriptorspec[$key] = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
);
$processes[] = proc_open($command, $descriptorspec[$key], $procPipes);
stream_set_blocking($procPipes[1], 0);
$pipes[$key] = $procPipes;
$output[$key] = '';
}
echo '<pre>';
do{
$allFinished = true;
foreach($processes as $key => $process){
$returnedValues = proc_get_status($process);
if($returnedValues['running']){
$allFinished = false;
$s = fread($pipes[$key][1],1024);
if($s){
$output[$key] .= $s;
print($s);
ob_flush();
flush();
}
}
}
} while($allFinished == false);
echo '</pre>';
foreach($processes as $process){
proc_close($process);
}
foreach($output as $o){
echo '<pre>'.print_r($o,true).'</pre>';
}
}
$commands = array();
$commands[] = "ping -n 5 127.0.0.1 2>&1";
$commands[] = "ping -n 5 10.0.0.1 2>&1";
//rtprocess($commands);