Home > Backend Development > PHP Tutorial > PHP实现定时执行任务的方法_PHP

PHP实现定时执行任务的方法_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-31 19:29:18
Original
913 people have browsed it

本文实例讲述了PHP实现定时执行任务的方法,代码简单实用。分享给大家供大家参考。

具体实现方法如下:

ignore_user_abort(true); //客户端断开时忽略脚本中止(允许脚本一直执行)
set_time_limit(0);  //设置脚本最长执行时间,0不限制
do{
  $handle = fopen('auto.txt', 'w');
  if($fp)
  {
    $text = '你好\n\r';
    $count = 0;
    for($i=1; $i<10; $i++)
    {
      if(! $c = fwrite($handle, '第'.$i.'行:'.$text)) //返回写入字符数,失败时返回false
      {
        echo '第'.$i.'次的写入失败!';
      }
      $count += $c;
    }
  }
  fclose($handle);
  sleep(60); //延缓60秒执行
}while(true);

Copy after login

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template