Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: how would you solve this? count
04-20-2012, 01:09 PM #1
- Join Date
- Jan 2012
- Thanked 0 Times in 0 Posts
how would you solve this? count
Hi all coders :P
I am going to do ( for me ) something like countdown ... to example 50s countdown... and when countdown will be 0 then do some php code... i think this will be no a problem because its just a JS and some connect to php. but... i have problem when a user have 50s ... then counter is counting down the numbers... 45 ... and counting and counting... 20 and when he is on number 20 (to example ) he decides close browser... but i want to do some php code after 50s even if he close the browser...
I hope i explained my problem well and u will help me figure out, how can i do it... THX A LOT!! :P
04-20-2012, 02:58 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,660 Times in 2,629 Posts
You can't. If you're using JS to invoke the script, once the user is gone that countdown is terminated since JS is client side.
PHP can only countdown based on sleep, and will only make the page appear as loading. PHP can be set to ignore_user_abort() if they leave the page.
Saying this, you can mix the two and invoke a JS right from the beginning that calls a PHP page that sleeps for 50 seconds and ignores user abort, then executes a given code block. You can also do this using just PHP, but it takes a little more work since you can't call the sleeping script in a conventional inclusion manner, you'll need to connect to it via an HTTP method such as curl so you can abandon it in the calling script. Otherwise your just wasting time with two scripts since it will hang up the calling script until its done anyway.