2014-08-30 40 views
1

從DreamHost捲曲Facebook API速度非常慢。有時會在1-2秒內回來,其他時間會在20秒後回來。它一直在搞亂我的網站。cURL在DreamHost緩慢服用~20秒

function curlUrl($url, $post = null) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101'); 

    if ($post): 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    endif; 

    $response = curl_exec($ch); 
    curl_close($ch); 
    return $response; 
} 

回答

3

添加curl_getinfocurl_exec表明,CONNECT_TIME非常緩慢。

$info = curl_getinfo($ch); 
print_r($info); 

發現這篇文章curl slow connect_time

添加此行加快東西一噸!

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);