Excerpt from: http://www.searchtb.com/2012/06/rolling-curl-best-practices.html
1 functionRolling_curl ($urls,$delay=0) {2 $queue=curl_multi_init ();3 $map=Array();4 5 foreach($urls as $url) {6 $ch=curl_init ();7 8curl_setopt ($ch, Curlopt_url,$url);9curl_setopt ($ch, Curlopt_timeout, 5);Tencurl_setopt ($ch, Curlopt_returntransfer, 1); Onecurl_setopt ($ch, Curlopt_header, 0); Acurl_setopt ($ch, Curlopt_nosignal,true); - -Curl_multi_add_handle ($queue,$ch); the $map[(string)$ch] =$url; - } -/* Main content */ - $responses=Array(); + Do { - while(($code= Curl_multi_exec ($queue,$active)) ==curlm_call_multi_perform); + A if($code! = CURLM_OK) { Break; } at - //a request was just completed--find out which one - while($done= Curl_multi_info_read ($queue)) { - - //get the info and content returned on the request - $info= Curl_getinfo ($done[' Handle ']);
Information from info can be used to determine if the connection is successful in $error= Curl_error ($done[' Handle ']); - //$results = Callback (Curl_multi_getcontent ($done [' Handle ']), $delay);
Curl_multi_getcontent ($done [' handle ']) has been able to get the details, that is, the business logic can be started
to $responses[$map[(string)$done[' Handle ']] =Compact(' Info ', ' error ', ' results ')); + - //Remove the curl handle that just completed theCurl_multi_remove_handle ($queue,$done[' Handle ']); *Curl_close ($done[' Handle ']); $ }Panax Notoginseng - //Block for data in/output; error handling was done by curl_multi_exec the if($active> 0) { +Curl_multi_select ($queue, 0.5); A } the +} while($active); -/* Main content */
curl_multi_close ($queuereturn $responses *
Rolling_curl Curl Bulk Collection function retention