I have the following code
<?php
if(isset($_POST['cond']){
echo '<br><p>Script to execute : xxxx.php<p>';
echo "<p>Executing</p>";
shell_exec('sleep 5');
echo "<p>Done</p>";
}
?>
Basically, the user clicks on a button that sends the 'cond' to the same page, which then enters the if
block. I want to warn the user when the script is starting to execute, then execute the script, then warn the user that script has been executed;
the current behavior is that the shell_exec('sleep 5')
must be executed entirely before the echo
statements are printed to the web page.
In fact, if you take the code inside the if
block and put in a blank page and try to load it, you have to wait the 5 seconds of sleep before the page even gets loaded, then you see the echo statements. I don't understand this behavior, PHP isn't Javascript and each line of code should be executed sequentially?
All are executed on a Debian GNU / Linux 9 remote server
Thanks in advance