This article mainly introduces the implementation method of simple timed execution tasks in php, involving operating techniques such as curl and sleep, and has certain reference points. Value, friends in need can refer to it
The example in this article describes the implementation method of simple scheduled execution of tasks in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
?
3 4 513 14
15
16
|
<🎜>ignore_user_abort();<🎜> <🎜>set_time_limit(0);<🎜> <🎜>$interval = 60*5;<🎜> <🎜>do{<🎜> <🎜>$url = "http://www.sina.com.cn/";<🎜> <🎜>$ch = curl_init();//Create a new curl session<🎜> <🎜>curl_setopt($ch,CURLOPT,$url);//Set the cURL to be crawled<🎜> <🎜>curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);<🎜> <🎜>//Set cURL parameters and require the result to be saved to a string or a page (1 or true means saving without output)<🎜> <🎜>curl_setopt($ch,CURLOPT_TIMEOUT,2);//Maximum duration 2 seconds<🎜> <🎜>$result = curl_exec($ch);//Execute<🎜> <🎜>curl_close($ch);//Close<🎜> <🎜>sleep($interval);//rest for 5 minutes<🎜> <🎜>}while(true);<🎜> <🎜>?> |