crontab定时脚本 编写规范

>".date('Y-m-d H:i:s')."\n";//生成日志文件开始时间(便于查看)
$ms = new Mysqls();
$min = 60*10;
$keyword = "钙";
$dated = date('Y-m-d H:i:s',time()-$min);
$date_name = '830';
$userid_str = '';
$i = 0;
$sql = "select********imit 500";
$data = $ms->getRows($sql);
foreach($data as $k => $v){
	$pattan = strpos($v['words'],$keyword);
	if($pattan !== false){
		M::Set('search_key_'.$v['user_id'].'_'.$date_name,1,time()+86400*3);
		$userid_str .=$v['user_id'].',';//暂存之后一次性写入
		$i++;
	}
}
if($userid_str != ''){
	file_put_contents('/opt/ci123/www/html/markets/app2/baby/badmin/cms/jiaoben/user_txt/search_user_'.$date_name.'.txt',$userid_str,FILE_APPEND);//尽可能少的减少对文件的操作
}
echo "查询总数据量>>".count($data)."\n";
echo "有效数据量>>".$i."\n";
echo "finsh>>".date('Y-m-d H:i:s')."\n\n\n\n\n";//生成日志文件结束时间(便于查看)

 

你可能感兴趣的:(linux,php)