Php 以不同的时间间隔执行任务

Php 以不同的时间间隔执行任务,php,pseudocode,Php,Pseudocode,我的mysql中有如下表: +----+---------------+--------------+----------------------+---------------------+ | id | report_name | report_id | rinterval | last_run | +----+---------------+--------------+----------------------+----------

我的mysql中有如下表:

+----+---------------+--------------+----------------------+---------------------+
| id | report_name   | report_id    | rinterval            | last_run            |
+----+---------------+--------------+----------------------+---------------------+
|  1 | test report 1 | 434234234234 | every morning        | 2016-05-20 12:55:07 |
|  2 | test report 2 | 3434232      | every sunday morning | 2016-05-20 12:55:07 |
|  3 | test report 3 | 342423423    | never                | 2016-05-20 12:55:07 |
|  4 | test report 4 | 4324234      | every morning        | 2016-05-20 12:55:07 |
+----+---------------+--------------+----------------------+---------------------+
我正在尝试创建一个php脚本(最好是),在调用该脚本时运行相应的报告。我想就最好的方法提出一些建议

假设我设置了一个cron作业,每天早上调用脚本,时间间隔如上(+类似):(每天早上、每个星期天、每个月两次,等等)。另外,我们假设,如果超过24小时,脚本不应该自动运行。也可以启动手动呼叫

我是这样想的:

Call script
Find what day and time it is
Find what day it is
Select * from above where day and time more than 24 hours
Iterate the above records and run the reports (report is run like http://example.com/report_name/report_id)
If rinterval reads "every morning" - run the report
If rinterval reads "every Sunday morning" - run the report if it is Sunday (and similar for other days using a case)
If rinterval reads "never" - do not run the report
if rinterval reads "twice a month" - find the last day run and see if the interval is more than 15 - if yes run it. (or similar)
在上述所有情况下,在成功运行时,更新上次运行时间戳。 我的一个问题是,如果我运行一个手动调用,或者如果我想每隔2分钟运行两个手动调用进行测试,会发生什么。如果我在周一下午运行报告,我仍然希望它在周二上午运行。我是否应该引入另一个专栏,指出这是手动呼叫还是自动呼叫?我仍然需要知道,如果是手动运行,那么运行是进行的,但我不想破坏计划,因为报告必须在上午8:00之前运行

你的想法是什么?我相信有一种更有效的方法可以做到这一点。我愿意接受所有建议,我是从零开始做这件事的

我的一个问题是,如果我运行一个手动调用,或者如果我想每隔2分钟运行两个手动调用进行测试,会发生什么

这取决于你的脚本在做什么

我仍然需要知道

然后简单地保存调用日志(单独的表),即脚本名称、调用日期、调用方式

我的一个问题是,如果我运行一个手动调用,或者如果我想每隔2分钟运行两个手动调用进行测试,会发生什么

这取决于你的脚本在做什么

我仍然需要知道


然后只需保存调用日志(单独的表),即脚本名称、调用日期、调用方式。

有更简单的方法可以做到这一点。Cron作业就是一个例子。任务调度是另一种方法(取决于您运行的服务器类型),有更简单的方法可以做到这一点。Cron作业就是一个例子。任务调度是另一种(取决于您运行的服务器类型)