-
- ignore_user_abort(); //Even if the Client is disconnected (such as closing the browser), the PHP script can continue to execute.
- 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
- $interval=60*5; // Run every 5 minutes
- do{
- $fp = fopen('test.txt' ,'a');
- fwrite($fp,'test');
- fclose($fp);
- sleep($interval); // Wait for 5 minutes
- }while(true);
- ?>
-
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:
-
-
*/5 * * * * lynx http://bbs.it-home.org
- Visits bbs.it-home.org every 5 minutes
- < p>0 8 * * * lynx http://bbs.it-home.org
- Visit bbs.it-home.org at 8 am every day
0 10 6 * 1-5 lynx http ://bbs.it-home.org
- Visit bbs.it-home.org on the 6th of every month and every Monday to Friday at 10am
0 5 7 8 * lynx http://bbs.it-home.org
- 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
|