Processing without any user interaction

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Processing without any user interaction

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

On Unix systems you could use cron.
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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).
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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...
Post Reply