先写个crontab,规律性的执行一个php脚本,比如2分钟一次。脚本中抓取任务执行前加个stockday判断,就可以了。stockday的实现如下:
function stockday(){
$w = date(“w”,time());
if($w==0||$w==6) return false;//周一到周五执行
//开盘时间大家都知道
$checkDayStr = date(‘Y-m-d ‘,time());
$timeBegin1 = strtotime($checkDayStr.”09:20:00″);
$timeEnd1 = strtotime($checkDayStr.”11:30:00″);
$timeBegin2 = strtotime($checkDayStr.”13:00:00″);
$timeEnd2 = strtotime($checkDayStr.”15:02:00″);
$curr_time = time();
if($curr_time >= $timeBegin1 && $curr_time <= $timeEnd1){
return true;
}
if($curr_time >= $timeBegin2 && $curr_time <= $timeEnd2){
return true;
}
return false;
}