Sometimes in order to adjust the interface regularly, the program needs to run automatically. From the Internet search, there are two ways to achieve this
1. ignore_user_abort()
The ignore_user_abort() function can be used with set_time_limit(0) and sleep($interval) to realize automatic program update.
Example: (As long as the following page is running, the program will continue to run even after the browser is closed)
http://blog.qita.in/?post=489
- //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, 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://www.yexiwei.com ”;
- $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
|