PHP定时任务延缓执行的实现_PHP

WBOY
Release: 2016-05-31 19:29:23
Original
1032 people have browsed it

代码如下:


/*
|---------------------------
|PHP定时任务
|@黑眼诗人
|---------------------------
*/
ignore_user_abort(true); //客户端断开时忽略脚本中止(允许脚本一直执行)

set_time_limit(0); //设置脚本最长执行时间,0不限制

do{
$fp = fopen('auto.txt', 'w');

if($fp)
{
$text = '你好\n\r';

$count = 0;

for($i=1; $i {
if(! $c = fwrite($fp, '第'.$i.'行:'.$text)) //返回写入字符数,失败时返回false
{
echo '第'.$i.'次的写入失败!';
}

$count += $i;
}
}

fclose($fp);

sleep(60); //延缓60秒执行

}while(true);

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template