content $mh = curl_multi_init(); $is_running = null; $handle_limit = 3; do { //fill up the curl queue at start of reqs and if any urls have finished while (sizeof($curling) < $handle_limit && sizeof($hosts) > 0) { $host = array_pop($hosts) ; $curling[$host] = curl_init( $host ); curl_setopt( $curling[$host], CURLOPT_CONNECTTIMEOUT, 10 ); curl_setopt( $curling[$host], CURLOPT_RETURNTRANSFER, true ); curl_multi_add_handle( $mh, $curling[$host] ); } // run curl curl_multi_exec($mh, $is_running); //pop finished hosts. //curl_multi_remove_handle also removes the downloaded data, so we stash it for later. $ready = curl_multi_select($mh); $info = curl_multi_info_read($mh); if ( $info && $info['msg']==CURLMSG_DONE ) { //copy response $host = curl_getinfo( $info['handle'], CURLINFO_EFFECTIVE_URL ); $http_code = curl_getinfo( $info['handle'], CURLINFO_HTTP_CODE ); /* only keep valid urls */ if ($http_code) { $content = curl_multi_getcontent( $info['handle'] ); $done[$host] = $content; } #print_r(curl_getinfo($info['handle'])); //remove from queue and close handles. curl_multi_remove_handle( $mh, $curling[$host] ); curl_close( $curling[$host] ); unset( $curling[$host] ); #echo "finished: $host\n"; } } while ($is_running>0); foreach($done as $host => $content) { #$results = curl_multi_getcontent( $curling[$i] ); #echo "$i:\n$results\n\n"; echo "\n$host\n$content\n"; } curl_multi_close($mh); echo "\ndone\n"; ?>