include()
在一个文件中的所有cron脚本,
所以当cron作业将在那个时候运行它会运行所有其他脚本,但是计时将是相同..
我们解决时间问题, 创建两个数据库表
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)
,并存储在最后时间的主人的cron已经跑值主表
last_ran_time (time)
value of last time when
cron has ran
备注:第二个表可以有多个条目,其中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
中获取...
让我知道如果任何问题......
'包括()'在一个cron的所有其它脚本...但脚本调用的时机将是相同...或更简单的需要时间和sc在你的数据库中篡改名字并给它们标记,如'0或1',0表示不运行,1表示运行... –
我可以建议看看supervisord –
@ AntonyD'Andrea,我真的不想用其他系统。这并不是那么复杂...... –