Sometimes in order to adjust the interface regularly, the program needs to run automatically. From the Internet, there are two ways to achieve this: 1. ignore_user_abort() The ignore_user_abort() function is combined with set_time_limit(0) and sleep($interval) to realize the automatic running and updating of the program.
-
- //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 is 30 seconds. By set_time_limit(0) allows the program to execute without limit
- set_time_limit(0);
- // Run every 5 minutes
- $interval=60*5;
- do{
- $url = “http://www.xxx. con";
- $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
|