CURL тестирует много ip-адресов URL одновременно: Ответ ПРОБЛЕМА - PullRequest
0 голосов
/ 18 августа 2011

Я делаю запрос скручивания на URL.Этот URL размещен на многих серверах ==> многих IP-адресов.Представьте, что "www.example.com" размещен на

  • 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 ( ) )**

, как вы видите: на некоторых серверах я НЕ 'T GET Информация о времени (все установлено на 0) есть ли проблемы с этим кодом?

1 Ответ

0 голосов
/ 18 августа 2011

Попробуйте установить CURLOPT_CONNECTTIMEOUT в 0 (ждать бесконечно) и посмотреть, поможет ли это.

...