0

I am using a PHP script on a local machine connected to an offline server. That server has a webpage on it that processes some homebrewed scripts. This all works fine. However, my setup currently looks something like this

<?php
echo shell_exec(./script1)
echo('Script 1 Done!' .PHP_EOL);
echo shell_exec(./script2)
echo('Script 2 Done!' .PHP_EOL);
echo shell_exec(./script3)
echo('Script 3 Done!' .PHP_EOL);
echo('All Done! .PHP_EOL);
?>

This is fine and works. However, each of these scripts have a ton of output. At seemingly random, arbitrary points in my code, the webpage refreshes and shows that output on a white background. I'm fine with this, except for the random, arbitrary points.

Is it possible to get this to do that in real time? I'm not even sure what to Google for this issue as nothing I've tried has seemed related.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Jibril
  • 967
  • 2
  • 11
  • 29

1 Answers1

0

Just capture the output in an array and then you can control when you want to output if you decide to at all.

<?php
$shellOutput = [];
$shellOutput[] = shell_exec('./script1');
$shellOutput[] = shell_exec('./script2');
$shellOutput[] = shell_exec('./script3');

//then when you want to output a simple foreach will do the trick.
foreach($shellOutput as $output){
    echo $output;
}

?>
jgetner
  • 691
  • 6
  • 14
  • Wouldn't this require the entire script to finish first? Am I missing something here? I'm not sure how i would be able to get this to display the outputs in real time. – Jibril Apr 27 '20 at 13:41
  • Yes this will capture each output after execution for all scripts. For real time display you will need to go another route and read the output and pass to view. https://stackoverflow.com/questions/20107147/php-reading-shell-exec-live-output – jgetner Apr 28 '20 at 10:51