Home  >  Article  >  Backend Development  >  定时实施php脚本

定时实施php脚本

WBOY
WBOYOriginal
2016-06-13 10:39:23831browse

定时执行php脚本
对于使用php的童鞋来说,计划任务大家首先想起的是linux下和crontab。但是并非所有人都是使用linux系统,也不是所有人都有独立服务器。这时候如何用php来实现计划任务呢。

所使用的函数是:  ignore_user_abort(),set_time_limit(0),sleep($interval)
此代码只要运行一次后关闭浏览器即可,但是这个方法也有一个问题,就是当重启了apache之后,脚本就被终止了,则需要再次运行。

ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{	//这里是你要执行的代码	sleep($interval);// 等待5分钟}while(true);


您可以任意转载本文,但转载时请以超链接形式标明文章原始出处和作者信息及版权声明
作者:赵烟哥,原文链接:http://www.o135.com/?p=474 [复制本文链接发送给您的好友]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn