以特定时间间隔(包括秒)安排任务

时间:2021-06-05 02:56:26

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

我有一个运行在标准linux,apache服务器上的php脚本。在某些情况下,我希望在用户执行某些操作后的15分钟内运行一个php脚本。 EG:用户访问时间为13:04:55,后台进程必须在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.

当前使用的解决方案是每分钟运行一次的cron并检查是否需要采取措施,但这并不准确,因为计时器在一分钟内完全运行且无法设置为秒。 EG:cron在13:04,13:20运行,依此类推。

Any recommendations on how to set these?

有关如何设置这些的任何建议?

Is there an alternative product / gearman any other simple solution?

是否有替代产品/齿轮师任何其他简单的解决方案?

3 个解决方案

#1


1  

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.

除了指定每个脚本的开头之间的间隔,或者从上一个脚本运行结束到下一个脚本开始之间的时间间隔之外,Fat Controller的工作方式与CRON类似。在任何一种情况下,您都可以以秒为单位指定时间,并提供各种策略来管理或阻止重叠运行。

Documentation, examples and download: http://fat-controller.sourceforge.net

文档,示例和下载:http://fat-controller.sourceforge.net

#2


0  

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.

拥有一个每分钟运行一次的cron作业,查看是否有任何作业需要在那一分钟运行,并在开始每个作业之前休眠适当的秒数。

#3


0  

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.

也许是一个简单的解决方案,例如在php中设置一个包含事件触发时间的会话变量。在每个后续页面上,您可以将会话变量加载到javascript计时器中,该计时器会在会话变量的开始时间与now()时间相等于15分钟时,在后台异步发生事件。

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.

这也可以让你使任务更加便携,而不是依赖于cron作业来做一些不在“正常”功能的事情。

Sources:

资料来源:

Jquery ajax call from javascript to PHP

Jquery ajax从javascript调用到PHP

Access PHP variable in JavaScript

在JavaScript中访问PHP变量

Difference between times in JavaScript

JavaScript中的时间差异

#1


1  

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.

除了指定每个脚本的开头之间的间隔,或者从上一个脚本运行结束到下一个脚本开始之间的时间间隔之外,Fat Controller的工作方式与CRON类似。在任何一种情况下,您都可以以秒为单位指定时间,并提供各种策略来管理或阻止重叠运行。

Documentation, examples and download: http://fat-controller.sourceforge.net

文档,示例和下载:http://fat-controller.sourceforge.net

#2


0  

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.

拥有一个每分钟运行一次的cron作业,查看是否有任何作业需要在那一分钟运行,并在开始每个作业之前休眠适当的秒数。

#3


0  

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.

也许是一个简单的解决方案,例如在php中设置一个包含事件触发时间的会话变量。在每个后续页面上,您可以将会话变量加载到javascript计时器中,该计时器会在会话变量的开始时间与now()时间相等于15分钟时,在后台异步发生事件。

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.

这也可以让你使任务更加便携,而不是依赖于cron作业来做一些不在“正常”功能的事情。

Sources:

资料来源:

Jquery ajax call from javascript to PHP

Jquery ajax从javascript调用到PHP

Access PHP variable in JavaScript

在JavaScript中访问PHP变量

Difference between times in JavaScript

JavaScript中的时间差异