项目需求
- 多个API接口,并且每个API接口的都有多个id需要读取;
- 每个API都设置读取启动开关和定时更新的时间间隔;
- 读取API后,将对应的内如自动录入到mysql数据库;
/*
* * isLock,是否开启报表任务,0关闭,1开启;
* */
//读取报表列表,判断是否开启报表任务;
$isLock = "";//开关
$sysTimeSpan = "";//系统间隔;
$groupsId = "";//组id
$report_id = "";//报表id;
//任务开启,执行定时任务;
if ($isLock == 1) {
classReminder($report_id, $sysTimeSpan, $groupsId, $table);
}
数据爬取并入库的封装函数
/*
* $sysTimeSpan,系统时间间隔,单位秒;
* */
function classReminder($report_id, $sysTimeSpan, $groupsId, $table)
{
//读取当前报表库的信息,判断最后一条的时间与当前时间的间隔;
$lasttime = "" . $table . "";
//当前时间;
$currtime = time();
//时间间隔;
$timeSpan = $currtime - $lasttime;
//判断时间是否大于系统设定时间;
if ($timeSpan > $sysTimeSpan) {
switch ($report_id) {
case "1":
foreach ($groupsId AS $v) {
$url = "" . $v;
$data = file_get_contents($url);
return $data;
}
break;
case 2:
echo 2;
break;
default:
echo "";
}
}
}
lockdatav Done!