Advertisement
Guest User

cURL Multi

a guest
Apr 1st, 2010
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?
  2.  $urls = array("ya.ru","google.ru","asdfasdfasfas.org","habr.ru");
  3.  
  4.  $tasks = array();
  5.  
  6.  $mh = curl_multi_init();
  7.  
  8.  foreach($urls as $url)
  9.  {
  10.   $h = curl_init("http://".$url);
  11.   curl_setopt($h,CURLOPT_FOLLOWLOCATION,1);
  12.   curl_setopt($h,CURLOPT_RETURNTRANSFER,1);
  13.   curl_setopt($h,CURLOPT_HEADER,0);
  14.   curl_multi_add_handle($mh,$h);
  15.   $tasks[$url] = $h;
  16.  }
  17.  
  18.  $act = 0;
  19.  
  20.  do
  21.  {
  22.   curl_multi_exec($mh,$act);
  23.   $info = curl_multi_info_read($mh);
  24.   if($info["msg"] == CURLMSG_DONE)
  25.   {
  26.    $h = $info["handle"];
  27.    $url = array_search($h,$tasks);
  28.    $tasks[$url] = curl_multi_getcontent($h);
  29.    curl_multi_remove_handle($mh,$h);
  30.    curl_close($h);
  31.   }
  32.  }
  33.  while($act > 0);
  34.  
  35.  curl_multi_close($mh);
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement