-
- //Even if the Client is disconnected (such as closing the browser), the PHP script can continue to execute.
- ignore_user_abort();
- //The execution time is unlimited, the default execution time of PHP It is 30 seconds. Through set_time_limit(0), the program can be executed without limit
- set_time_limit(0);
- // Run every 5 minutes
- $interval=60*5;
- do{
- $url = “http:// /bbs.it-home.org";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 2 );
- $result = curl_exec($ch);
- curl_close($ch);
- // Wait for 5 minutes
- sleep($interval);
- }while(true);
- ?>
-
Copy code
As long as you run the page above and then close it, the program will continue to run.
2. crontab
The function of the crontab command is to schedule the execution of some commands at certain intervals.
How to use crontab: crontab [ -e | -l | -r ] file name -e: edit task -l: display task information -r: delete scheduled execution task information
The format of crontab:
-
- */5 * * * * /usr/bin/curl "http://bbs.it-home.org"
- #Visit bbs.it-home.org every 5 minutes
Copy Code
You may also like:
The implementation principle of PHP scheduled tasks
How to execute PHP program regularly with crontab under Linux
|