Home >Backend Development >PHP Tutorial >How to implement scheduled tasks in PHP, implement tasks in PHP_PHP tutorial

How to implement scheduled tasks in PHP, implement tasks in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:481132browse

PHP implements the method of regularly executing tasks, php implements tasks

The example in this article describes how to implement scheduled tasks in PHP. The code is simple and practical. Share it with everyone for your reference.

The specific implementation method is as follows:

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);

I hope this article will be helpful to everyone’s PHP programming design.

How to implement scheduled execution of scripts in PHP?

If you want to use PHP files, you can barely do it
There is a sleep function in php. The specific use is sleep(time) where time is in seconds
First, create a php script
3b48858bc2202882e5ec5ab9726fc208
The yourcode here is the function you want the PHP script to execute. Although this goal can be achieved, there are sacrifices. You have to access this script through the URL at 8 o'clock in the morning, which means executing the PHP file, and this link cannot be interrupted and must continue! ! Otherwise, it will be invalid

PHP is executed only upon request, and is executed only when there is a request.

How to use PHP language to make the system execute a task regularly?

06f45c8b796589a4e319dedfacef2cde

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/889137.htmlTechArticleHow to implement scheduled tasks in PHP, and how to implement tasks in PHP. This article describes how to implement scheduled tasks in PHP, and the code Simple and practical. Share it with everyone for your reference. Specific implementation...
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