Advertisement
Guest User

PHP Bug Report Multi Curl

a guest
Oct 30th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.     $curlInits  = array();
  3.     $mh         = curl_multi_init();
  4.     $urls       = array(
  5.             "http://www.google.co.uk",
  6.             "http://www.reddit.com"
  7.         );
  8.     $key        = 0;
  9.     foreach ( $urls as $link)
  10.     {
  11.       $curlInits[$key] = curl_init();
  12.       curl_setopt($curlInits[$key], CURLOPT_URL, $link);
  13.       curl_setopt($curlInits[$key], CURLOPT_RETURNTRANSFER, 1);
  14.       curl_multi_add_handle($mh,$curlInits[$key]);
  15.       $key++;
  16.     }
  17.  
  18.     $active = 1;
  19.     do {
  20.         $mrc = curl_multi_exec($mh, $active);
  21.     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  22.  
  23.     while ($active && $mrc == CURLM_OK) {
  24.         if (curl_multi_select($mh) != -1) {
  25.             do {
  26.                 $mrc = curl_multi_exec($mh, $active);
  27.             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  28.         }
  29.     }
  30.     $results = array();
  31.  
  32.     $key = 0;
  33.     foreach($urls as $link)
  34.     {
  35.       $response = curl_multi_getcontent( $curlInits[$key]   );
  36.       // Add to results array
  37.       $results[] = $response;
  38.       $key++;
  39.     }
  40.     curl_multi_close($mh);
  41.     print_r($results);
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement