Page 1 of 1

Processing without any user interaction

Posted: Tue Jan 08, 2008 1:18 am
by bebensiganteng
Hi guys,

Is it possible to execute an action in a specific time through the server without any user interactions?

Let say:
A user plays an on line chess game but at the middle of the game he decided to finish it, he closed the browser (because maybe the application is taking too long to think about the next move).
But even though the browser is closed, the game is still thinking about its next move, and when it executed the move the game will send a notification to the user via email

Thanks in advance

Posted: Tue Jan 08, 2008 1:29 am
by Christopher
On Unix systems you could use cron.

Posted: Tue Jan 08, 2008 3:05 am
by Maugrim_The_Reaper
You can allow a PHP process to continue execution past the time a user closes the browser using ignore_user_abort(). The trick to this however that you need to send something back to the browser before it closes. Typically this means echoing/printing something, and calling flush() to ensure all buffered data (whether PHP, CGI or Apache) is sent. From that point on, ignore_user_abort(true) allows PHP to continue executing in it's current process even if the user closes the connection.

There are various other strategies also possible, including an AJAX style one which may be useful if for some reason the ignore_user_abort() function is not available on your system (sometimes due to shared hosting security).

Posted: Tue Jan 08, 2008 11:05 am
by alex.barylski
Ohhhh...thats killer Maugrim... :D

I'm curious though how you eventually might decide to kill a script? I wonder if the same could be accomplished using CLI and the sleep function...if CLI was supported that is...