Reputation: 2247
I have a php script that runs on a standard linux, apache server. In certain cases I would like to have a php script run exactly 15 minutes after certain action was performed by an user. EG: user visit at 13:04:55 and the background process has to run exactly at 13:19:55
The current solution used is a cron that runs every minute and checks if action is needed but this is not accurate as timer runs exactly on a minute and cant be set to the seconds. EG: cron runs at 13:04, 13:20 and so on.
Any recommendations on how to set these?
Is there an alternative product / gearman any other simple solution?
Upvotes: 0
Views: 709
Reputation: 2384
The Fat Controller works similarly to CRON except you specify the interval between either the starts of each script, or the time from the end of the previous script's run until the start of the next. In either case you can specify the time in seconds and provides various strategies for managing or preventing overlapping runs.
Documentation, examples and download: http://fat-controller.sourceforge.net
Upvotes: 1
Reputation: 83
Perhaps a simple solution such as setting a session variable in php that contains the time the event was triggered. On every subsequent page you can load the session variable into a javascript timer that has an event that happens asynchronously in the background once the session variable's start time compared to the now() time is equal to 15 minutes.
This would also allow you to make the task more portable instead of depending on a cron job to do something that is not in its "normal" function.
Sources:
Jquery ajax call from javascript to PHP
Access PHP variable in JavaScript
Difference between times in JavaScript
Upvotes: 0
Reputation: 281485
Have a cron job that runs every minute, sees whether any jobs need running that minute, and sleeps for the appropriate number of seconds before starting each job.
Upvotes: 0