Jump to content

PHP Sleep Doesn't Sleep


Recommended Posts

I have this code:

<html>
<body>

<?php

echo date('h:i:s'), "<br>";
sleep(5); 
echo date('h:i:s'), "<br>";
echo "Your Pizza: ", $_POST["Pizza"];
echo " Has Been Sent To The Counter";

?>



</body>
</html>

which gives me this result:

07:41:06
07:41:06
Your Pizza: Thin & Crispy, , Garlic, Sweetcorn, Chicken, Bacon, Spicy Beef, Cooked, Has Been Sent To The Counter

I can't seem to get the page to sleep at all. 

 

My intention is to achieve this a page that will display the message above for 5 seconds then run a relocation to the main page. but for now just making the page sleep would be of benefit.

 

any help would be appreciated. I am a beginner so I am expecting this to be something simple i have missed.

Link to post
Share on other sites

a. the echoed time values should have been correct. are you sure about the posted code and the output that you got?

b. browsers and web servers don't interact in real-time. even if you try to flush() the output, you are not very likely to get the result you want (see the php.net documentation for the flush() statement to see all the problems with trying to do it this way.)

c. people don't like to wait on web pages to display things for x amount out time (it's either too long of a value or too short of one to suit the current visitor) or to redirect around on your site. the only redirect you have upon successful completion of post method form processing code should be to the exact same url of the current page to cause a get request for that page. if you want to display a one-time success message, store it in a session variable, then test/display/clear that session variable at the appropriate place in the html document. any navigation to other pages should be handled using navigation links where the visitor can choose where they want to go to next.

  • Thanks 1
Link to post
Share on other sites
4 hours ago, mac_gyver said:

a. the echoed time values should have been correct. are you sure about the posted code and the output that you got?

b. browsers and web servers don't interact in real-time. even if you try to flush() the output, you are not very likely to get the result you want (see the php.net documentation for the flush() statement to see all the problems with trying to do it this way.)

c. people don't like to wait on web pages to display things for x amount out time (it's either too long of a value or too short of one to suit the current visitor) or to redirect around on your site. the only redirect you have upon successful completion of post method form processing code should be to the exact same url of the current page to cause a get request for that page. if you want to display a one-time success message, store it in a session variable, then test/display/clear that session variable at the appropriate place in the html document. any navigation to other pages should be handled using navigation links where the visitor can choose where they want to go to next.

a. Yes the code is posted and the output are correct to my results. maybe the server I am using is having problems. (It is a free server)

b. I will have a look at the Flush() statement now, thankyou

c. You make a valid point, I will look into this on both sides of my code! Thanks Again.

Link to post
Share on other sites
4 hours ago, Barand said:

A meta-refresh will do what you want


<?php
echo "Your pizza is ready<br>";
echo "<meta http-equiv=\"refresh\" content=\"5; url='url-to-go-to'\" />"  
?>

 

Thankyou for this bit of code. It has done exactly what I needed. though I have not seen it before, Where could I find information on it?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.