Understand the implementation principle of PHP scheduled tasks

WBOY
Release: 2016-07-25 09:03:12
Original
1062 people have browsed it
  1. ignore_user_abort(); //Even if the Client is disconnected (such as closing the browser), the PHP script can continue to execute.
  2. set_time_limit(0); //The execution time is unlimited, php The default execution time is 30 seconds. Through set_time_limit(0), the program can be executed without limit
  3. $interval=60*5; // Run every 5 minutes
  4. do{
  5. $fp = fopen('test.txt' ,'a');
  6. fwrite($fp,'test');
  7. fclose($fp);
  8. sleep($interval); // Wait for 5 minutes
  9. }while(true);
  10. ?>
Copy the code

Just run the page above and then close it, the program will keep running.

There are simpler crontab commands in linux.

The function of the crontab command is to schedule the execution of some commands at a certain time interval.

How to use crontab: crontab [ -e | -l | -r ] file name -e: edit task -l: display task information -r: delete scheduled execution task information

crontab format: * * * * * Command Minute Hour Day Month Week Command to run

crontab example:

  1. */5 * * * * lynx http://bbs.it-home.org

  2. Visits bbs.it-home.org every 5 minutes

  3. < p>0 8 * * * lynx http://bbs.it-home.org
  4. Visit bbs.it-home.org at 8 am every day

  5. 0 10 6 * 1-5 lynx http ://bbs.it-home.org

  6. Visit bbs.it-home.org on the 6th of every month and every Monday to Friday at 10am

  7. 0 5 7 8 * lynx http://bbs.it-home.org

  8. Visit bbs.it-home.org at 5 am on August 7th

Copy code

Explanation: "*" represents all numbers within the value range, "/" represents every, "*/5" represents every 5 units, "-" represents from a certain number to a certain number, "," means how many units to separate. a discrete number.

This article is reproduced from: http://hi.baidu.com/andylu1988/item/9674d31406ed61008ebde4b6



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!