实时服务器上的cURL很慢,但在localhost

时间:2015-05-01 09:11:14

标签: php curl

我使用cUrl(php)来获取网页的代码html。 它在localhost上运行得非常快(等待时间:700毫秒)。但是当我部署到实时服务器时,它运行速度非常慢(等待时间:5,6s)。 我怎么修理它?

function getHTML($url,$timeout)
{
    $ch = curl_init($url); // initialize curl with given url
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101');
    return @curl_exec($ch);
}

,这是我在print_r(curl_getinfo($ ch))时的结果:

Array ( 
    [url] => http://vozforums.com/showthread.php?t=6693 
    [content_type] => text/html; charset=UTF-8 
    [http_code] => 200 
    [header_size] => 535 
    [request_size] => 195 
    [filetime] => -1 
    [ssl_verify_result] => 0 
    [redirect_count] => 0 
    [total_time] => 2.375209 
    [namelookup_time] => 0.000561 
    [connect_time] => 0.310456 
    [pretransfer_time] => 0.310458 
    [size_upload] => 0 
    [size_download] => 107726 
    [speed_download] => 45354 
    [speed_upload] => 0 
    [download_content_length] => 107726 
    [upload_content_length] => 0 
    [starttransfer_time] => 0.74337 
    [redirect_time] => 0 
    [redirect_url] => 
    [primary_ip] => 1xx.xx.xx.xx 
    [certinfo] => Array ( ) 
) 

0 个答案:

没有答案