PHP CURL Multithreading Get/post class2015-01-01 Category: Technical articles read (623) Comments (0)
If there is a need to correct or more efficient suggestions, welcome to share ~\ (≧▽≦) in Oschina/~
http://www.oschina.net/code/snippet_1475115_44902
<?PHP/**************************************************************** PHP CURLMultithreadingGet/post email:[email protected]/qq:690204663 Powered by XiaosangCurl(Array (' Url?get=data ', ' url '), Array (' ', ' post_data ')); *****************************************************************/ function Curl($urls,$post) {$queue= Curl_multi_init();$map=Array(); Foreach ($urlsAs$key=$url) {$ch=Curl_init();curl_setopt($ch,Curlopt_url,$url);curl_setopt($ch,Curlopt_timeout, 30);curl_setopt($ch,Curlopt_returntransfer, 1);curl_setopt($ch,Curlopt_postfields,$post[$key]);curl_setopt($ch,Curlopt_header, 0);curl_setopt($ch,Curlopt_nosignal, True);Curl_multi_add_handle($queue,$ch);$map[(String)$ch] =$url; }$responses=Array(); Do { While (($code=Curl_multi_exec($queue,$active)) ==Curlm_call_multi_perform) ; If ($code!=Curlm_ok) { Break; } While ($done=Curl_multi_info_read($queue)) {$error=Curl_error($done[' Handle ']);$results=Curl_multi_getcontent($done[' Handle ']);$responses[$map[(String)$done[' Handle ']]] =Compact(' Error ', ' Results ');Curl_multi_remove_handle($queue,$done[' Handle ']);Curl_close($done[' Handle ']); } If ( $active > 0) { Curl_multi_select ( $queue , 0.5); } } while $active Curl_multi_close $queue return $responses ; /span>
PHP CURL multithreaded Get/post class