Home > Backend Development > PHP Tutorial > A small example of php scheduled tasks

A small example of php scheduled tasks

WBOY
Release: 2016-07-25 08:58:54
Original
1036 people have browsed it
  1. //When it is 0, close the scheduled task
  2. return 1;
  3. ?>
Copy code

2, jbxue.php

  1. ignore_user_abort();//Close the browser and the PHP script can continue to execute.
  2. set_time_limit(0);//The program can be executed without limit through set_time_limit(0)
  3. $interval=60*3;//Run every 3 minutes
  4. $ii=0;
  5. do{
  6. $run = include 'jhrw.conf.php';
  7. if(!$run) {
  8. file_put_contents("tasktest .txt","==Scheduled task has ended==rn",FILE_APPEND);
  9. die('Job has ended.');
  10. }
  11. //Put the code to be executed here
  12. sleep($interval);/ / Wait for 3 minutes
  13. $nowTime = date("Y-m-d H:m:s");
  14. $data="$ii>The scheduled task is running... (Running status: $run) $nowTimern";
  15. file_put_contents( "tasktest.txt", $data,FILE_APPEND);
  16. $ii++;
  17. }while(true);
  18. //by bbs.it-home.org
  19. ?>
Copy code

Mainly change jbxue. Return 0 in conf.php can control the shutdown of this scheduled task.



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