Please excuse what may seem like a very simple question and may lack of understanding of how PHP/sleep() works, but I was after some guidance on the following code:
<?php
$time_now = time();
echo "Time Now : " . $time_now;
sleep(10);
$time_then = time();
echo "<br>Time Then : " . $time_then;
?>
I was expecting this code to output the current time, then wait 10 seconds, then output the time 10 seconds later.
Instead it waits the 10 seconds set and outputs both the times at the same time. The times ARE correct in that the 'Time Now' is when I executed the code, and the 'Time Then' is 10 seconds later, but it does not respond how I expected (output Time Now, wait 10 seconds, then continue to execute the code and show 'Time Then').
Given that my understanding is clearly incorrect, is it possible to achieve this? Or would I be better to trigger another file to load what I want to do as follows:
File 1
<?php
$time_now = time();
echo "Time Now : " . $time_now;
header('Location: page2.php');
?>
File 2
<?php
sleep(10);
$time_then = time();
echo "<br>Time Then : " . $time_then;
?>
Thank you.