2011-08-18 38 views
0

正在對URL進行curl請求。這個URL由許多服務器託管==>許多IP地址。 想象 「www.example.com」 由CURL同時測試一個url的很多ip地址:響應問題

  • 192.168.60.31
  • 198.166.15.15
  • 217.15.74.1

這裏舉辦的是,我做了測試:

public function curlInfosMulti($ips,$url, $timeout, $method, $params) { 



     $count= count($ips); 
     $container = array(); 
     $tab = array('Host:'.$url); 
// set URL and other appropriate options 
     for ($i=0; $i<$count; $i++) 
     { 
      $container[$i] = curl_init(); 
      curl_setopt($container[$i], CURLOPT_URL, $ips[$i]); 
      curl_setopt($container[$i], CURLOPT_HTTPHEADER, $tab); 
      curl_setopt($container[$i], CURLOPT_HEADER, 1); 
      curl_setopt($container[$i], CURLOPT_RETURNTRANSFER, true); 
     } 


//create the multiple cURL handle 
     $mh = curl_multi_init(); 



     for ($i=0; $i<$count; $i++) 
     { 
      curl_multi_add_handle($mh, $container[$i]); 
     } 









     $running = null; 
//execute the handles 
     do { 
      curl_multi_exec($mh, $running); 
     } while ($running > 0); 

     $response_1 = curl_multi_getcontent($container[1]); 
     //$response_2 = curl_multi_getcontent($ch2); 
     $infos0 = curl_getinfo($container[0]); 
     $infos1 = curl_getinfo($container[1]); 
     $infos2 = curl_getinfo($container[2]); 
     $infos3 = curl_getinfo($container[3]); 
     $infos4 = curl_getinfo($container[4]); 
     $infos5 = curl_getinfo($container[5]); 

     print_r($infos0); 
       echo '</br></br></br>'; 
     print_r($infos1); 
       echo '</br></br></br>'; 
     print_r($infos2); 
     echo '</br></br></br>'; 
     print_r($infos3); 
     echo '</br></br></br>'; 
     print_r($infos4); 
     echo '</br></br></br>'; 
     print_r($infos5); 

//close the handles 

      for ($i=0; $i<$count; $i++) 
     { 

     curl_multi_remove_handle($mh, $container[$i]); 
     } 
     curl_multi_close($mh); 
    } 

這裏的問題是,當我想象的信息我得到這個:

**Array ([url] => HTTP://195.81.228.5 [content_type] => text/html; charset=utf-8 [http_code] => 200 [header_size] => 354 [request_size] 
=> 53 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.138 [namelookup_time] => 0.998 [connect_time] => 
1.045 [pretransfer_time] => 1.045 [size_upload] => 0 [size_download] 
=> 8387 [speed_download] => 7369 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 1.092 [redirect_time] => 0 [certinfo] => Array ()) 


Array ([url] => HTTP://195.81.228.17 [content_type] => text/html; charset=utf-8 [http_code] => 200 [header_size] => 354 [request_size] 
=> 53 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.138 [namelookup_time] => 0.998 [connect_time] => 
1.045 [pretransfer_time] => 1.045 [size_upload] => 0 [size_download] 
=> 8387 [speed_download] => 7369 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 1.092 [redirect_time] => 0 [certinfo] => Array ()) 


Array ([url] => HTTP://195.81.228.37 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 22.136 [namelookup_time] => 0.998 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ()) 


Array ([url] => HTTP://195.81.228.39 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 22.136 [namelookup_time] => 0.998 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ()) 


Array ([url] => HTTP://195.81.228.40 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 22.136 [namelookup_time] => 0.998 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ()) 


Array ([url] => HTTP://195.81.228.41 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 22.136 [namelookup_time] => 0.998 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ())** 

正如你看到的:在某些服務器上我沒有得到時間信息(一切都被設置爲0) 是有這個代碼的任何問題嗎?

回答

0

嘗試將CURLOPT_CONNECTTIMEOUT設置爲0(等待無限期)並查看是否有幫助。

+0

我得到了同樣的結果! – ProXamer

+0

仍然一切爲0(對於最後4個IP) – ProXamer

+0

您是否檢查過這些地址是否可以通過其他方法獲得,例如使用您的瀏覽器? – F21