运行 php 没有 crontab 的脚本
Run php scripts without crontab
我的 crontab 有大约 200 多个计划作业,真的很难记住什么时候应该使用什么参数 运行。而且更难记住所有脚本名称。如果团队中的某个人删除一些作业,我会遇到麻烦 - crontab 已备份,但你要恢复它我应该担心某些内容已被删除或只是被删除。
所以我正在考虑创建一个将启动所有其他作业的单个 cron 作业,该作业将保存在数据库中并通过 Web 界面进行管理。
我现在有一个问题。它是如何设置类似 crontab 的频率的 - 我的意思是这样的:* * 1 * *。当我的单个脚本启动时,它应该很容易知道哪个脚本应该是 运行。我需要一个建议,因为现在我能想到的就是测量每个 运行.
上的 time()%
include()
单个文件中的所有 cron 脚本,
所以当 cron 作业将 运行 时,它将 运行 所有其他脚本,但时间将相同..
现在解决时间问题,
创建两个数据库 tables
1) Cron
id(int 11) name(varchar) flag(enum)
Auto Increament ID name of php file enabled/disabled
2) CronTimings
id(int 11) fk_cron_id (int 11) time (time) day(varchar)
Auto incr foreign key of first table time to run the script CSV days (i.e. Mon,Tue,Wed)
和一个主 table 存储上次主 cron 具有 运行
时的值
last_ran_time (time)
value of last time when
cron has ran
注意: 第二个 table 可以有多个 fk_cron_id
条目。 (一个脚本可以有多个时间)
现在在您的单个 cron 文件中
$last_ran = "05:02:15"; // from the master table
$day = date('D');
$qry = "select * from cron c
left join cronTimings ct on ct.fk_cron_id = c.id
where ct.id in (select id from cronTimings where day like = '%".$day."%') and ct.time between '$last_ran' and '".date('H:i:s')."'";
//fetch data
foreach($crons as $crn)
{
include($crn['file'])
}
你可以每半小时或一小时 运行 这个文件,所以如果任何 cron 必须在这段时间内 运行,它将使用 mysql between
获取...
如果有任何问题请告诉我...
我的 crontab 有大约 200 多个计划作业,真的很难记住什么时候应该使用什么参数 运行。而且更难记住所有脚本名称。如果团队中的某个人删除一些作业,我会遇到麻烦 - crontab 已备份,但你要恢复它我应该担心某些内容已被删除或只是被删除。
所以我正在考虑创建一个将启动所有其他作业的单个 cron 作业,该作业将保存在数据库中并通过 Web 界面进行管理。
我现在有一个问题。它是如何设置类似 crontab 的频率的 - 我的意思是这样的:* * 1 * *。当我的单个脚本启动时,它应该很容易知道哪个脚本应该是 运行。我需要一个建议,因为现在我能想到的就是测量每个 运行.
上的 time()%include()
单个文件中的所有 cron 脚本,
所以当 cron 作业将 运行 时,它将 运行 所有其他脚本,但时间将相同..
现在解决时间问题, 创建两个数据库 tables
1) Cron
id(int 11) name(varchar) flag(enum)
Auto Increament ID name of php file enabled/disabled
2) CronTimings
id(int 11) fk_cron_id (int 11) time (time) day(varchar)
Auto incr foreign key of first table time to run the script CSV days (i.e. Mon,Tue,Wed)
和一个主 table 存储上次主 cron 具有 运行
时的值last_ran_time (time)
value of last time when
cron has ran
注意: 第二个 table 可以有多个 fk_cron_id
条目。 (一个脚本可以有多个时间)
现在在您的单个 cron 文件中
$last_ran = "05:02:15"; // from the master table
$day = date('D');
$qry = "select * from cron c
left join cronTimings ct on ct.fk_cron_id = c.id
where ct.id in (select id from cronTimings where day like = '%".$day."%') and ct.time between '$last_ran' and '".date('H:i:s')."'";
//fetch data
foreach($crons as $crn)
{
include($crn['file'])
}
你可以每半小时或一小时 运行 这个文件,所以如果任何 cron 必须在这段时间内 运行,它将使用 mysql between
获取...
如果有任何问题请告诉我...