jahicki Posted September 4, 2020 Share Posted September 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/ Share on other sites More sharing options...
mac_gyver Posted September 4, 2020 Share Posted September 4, 2020 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/#findComment-1581157 Share on other sites More sharing options...
Barand Posted September 4, 2020 Share Posted September 4, 2020 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'\" />" ?> 1 Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/#findComment-1581159 Share on other sites More sharing options...
jahicki Posted September 4, 2020 Author Share Posted September 4, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/#findComment-1581164 Share on other sites More sharing options...
jahicki Posted September 4, 2020 Author Share Posted September 4, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/#findComment-1581165 Share on other sites More sharing options...
Barand Posted September 4, 2020 Share Posted September 4, 2020 https://lmgtfy.com/?q=html+meta+refresh Quote Link to comment https://forums.phpfreaks.com/topic/311431-php-sleep-doesnt-sleep/#findComment-1581167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.