简单计划任务,至于效率。。。。
//新建index.php文件,指定每五秒写入文件一次
ignore_user_abort();//关闭浏览器后,继续执行php代码
set_time_limit(0);//程序执行时间无限制
$sleep_time = 5;//多长时间执行一次
$switch = include 'abc.php';
while($switch){
$switch = include 'abc.php';
$fp = fopen('test.txt','a+');
fwrite($fp,"执行 $switch \n");
fclose($fp);
sleep($sleep_time);
}
exit();
在新建另一个 abc.php,写入
return 0;//1执行脚本 0退出执行脚本
使用浏览器运行index.php 程序就会制动执行,会每隔5秒执行一次像text文件中,写入一条数据。需要关闭时,把abc.php文件 return值改为0