Reputation: 613
I want to draw text after 1 second delays, without halting the page load for the duration of all of the delays in total.
Does anyone know how?
I have the below, but rather than drawing the TIME and "Hello", then waiting a second and drawing "Goodbye", followed by another second and finally "The End".... It waits 2 seconds and then draws everything.
<?php
echo date('H:i:s');
echo "<br>";
echo 'Hello';
echo "<br>";
sleep(1);
flush();
echo 'Goodbye';
echo "<br>";
sleep(1);
flush();
echo 'The End';
?>
Upvotes: 0
Views: 2523
Reputation: 2009
You can use jQuery in somewhat this way: (Assuming that your text is initialised with hello)
$('#id-of-your-tag-containing-text').fadeOut(500, function() {
$('#id-of-your-tag-containing-text').html("GoodBye!");
$('#id-of-your-tag-containing-text').fadeIn(500);
$('#id-of-your-tag-containing-text').fadeOut(500, function() {
$('#id-of-your-tag-containing-text').html("The End!");
});
$('#id-of-your-tag-containing-text').fadeIn(500);
}); //Note that the number 500 represents the time delay in milliseconds.
Upvotes: 1
Reputation: 3396
As PHP is executed server-side, the user won't get the output until the script is finished executing. To add a visible delay of outputting messages, you would have to use JavaScript or another Client-Side executed scripting language.
Upvotes: 3