简体   繁体   English

cURL真的很慢

[英]cURL really slow

Does anybody know why could cURL under php5 be so damn slow to fail even at 45s timeout, downloading a few kb file on a speedO'light server? 有没有人知道为什么在php5下cURL即使在45s超时也无法缓慢失败,在speedO'light服务器上下载几个kb文件?

The code is here as requested (although I upped the timeouts even more for the script not to fail during execution and changed useragent to Mozilla/4.0 from initial Chrome): 这里的代码按照要求提供(尽管我在执行过程中不会因为脚本失败而将更多的超时时间提高,并且将初始Chrome中的useragent更改为Mozilla / 4.0):

$ch = curl_init('http://www.somesite.com/' . $key);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.somesite.com/somereferer/');
// curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0');
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 600);

hmm, could be a few things, maybe some verbose output will have an error of some kind 嗯,可能是一些事情,也许一些详细的输出会有某种错误

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true); // some output will go to stderr / error_log
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$response = curl_exec($ch);
$errStr = curl_error($ch);
$errNum = curl_errno($ch);
$head = curl_getinfo($ch, CURLINFO_HEADER_OUT);
$ci = curl_getinfo($ch);
print_r(array($head, $errStr, $errNum, $ci));

Sometimes the user agent will change how a site responds, may need to do something like: 有时,用户代理会更改网站的响应方式,可能需要执行以下操作:

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101');

When I set a CONNECTtimeout, I get faster response. 当我设置CONNECTtimeout时,我得到更快的响应。 Including this option: 包括此选项:

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM