0

Hi,

I have some queries that update some statistics in a table I have. I need these queries to run only after 15 seconds have passed however. This way if the user leaves before the 15 seconds, the queries won't run. I've tried using Sleep, however it seems to just stop all the code all together for the allotted time. There must be a way to do this. :)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by james.newell
0

Hi Smudly,

As you have noticed, the PHP sleep function delays the script execution until the number of seconds is up. Consequently the user receives no feedback until after the sleep has finished and the script provides some output causing the page to look dead.

The less desirable (but easier) way to achieve your goal could be implemented using a HTML meta refresh to redirect the user after 15 seconds to another page that performs the queries.

The best way to achieve your goal would be using AJAX. You could set a timeout for 15 seconds which dynamically loads the results of the queries into the current page (the advantage being that the user doesn't have to load a whole new page as the previous method does).

Hope this heads you in the right direction,

James

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.