PHP程序定时执行
1 ignore_user_abort(true);//关闭浏览器后,脚本继续执行 2 set_time_limit(0);//清除脚本执行时间限制 3 4 function write_txt() 5 { 6 if(!file_exists("_test/test.txt")){ 7 $fp = fopen("_test/test.txt","wb"); 8 fclose($fp); 9 } 10 $str = file_get_contents('_test/test.txt'); 11 $str .= "\r\n".date("Y-m-d H:i:s"); 12 $fp = fopen("_test/test.txt","wb"); 13 fwrite($fp,$str); 14 fclose($fp); 15 } 16 17 function do_cron(){ 18 sleep(30);//程序延迟30s执行 19 write_txt(); 20 } 21 22 while(1){ 23 do_cron(); 24 }

浙公网安备 33010602011771号