从DreamHost卷曲Facebook API非常慢。有时它会在1-2秒内恢复,其他时间则为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;
}
答案 0 :(得分:3)
在curl_getinfo
之后添加curl_exec
,表明connect_time非常慢。
$info = curl_getinfo($ch);
print_r($info);
找到这篇文章curl slow connect_time
添加这条线加速了一吨!
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );