Rolling_curl Curl Bulk Collection function retention

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.