views:

26

answers:

1

My objective is to run a function every seconds. And check some time based functionality. For example, In my application I have five groups of users. Each of the users have a particular task. And allotted a particular period of time. The task firstly assigned to the lower level(ie, 5th level) Users. If that users couldnot able to clear the task with the allotted time, it will automatically reassign to the next higher level of users(here 4 th level). My table structure is Users-> name,allotted time Tasks->task title,task description. If anybody know the solution, please help me.

Thanks in advance.

+1  A: 

You need to set up a cron task in your operating system (Unix, Windows, etc.) that will call a CakePHP shell script each interval.

http://book.cakephp.org/view/846/Running-Shells-as-cronjobs.

Or if you want it to only run while a user has a particular page loaded, then you could use JavaScript to make AJAX calls at intervals.

http://roshanbh.com.np/2008/03/call-php-ajax-every-second-jquery.html

(I make no guarantee about either of these links, I found each after about 5s of Googling.)

Dan Berlyoung
Be careful when using a cron job, especially if you're calling it every couple of seconds. In that situation, if it takes longer than the interval between calls, you could be running 2 of the same jobs at once, which (depending on what and how you're doing things) could really cause problems.
Travis Leleu