libcurl - 5 秒后出现奇怪的超时
我正在使用 libcurl 与 Twitter 和 Identi.ca 进行通信。只要我的连接不忙,一切都会正常工作。但如果我下载一个大文件,curl 请求会在 5 秒后超时。
我在curl句柄上设置了以下选项:
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 15);
它们没有区别,curl_easy_perform()
总是在5秒后返回。 CURLINFO_RESPONSE_CODE
和 CURLINFO_HTTP_CONNECTCODE
值始终为零。
有什么想法吗?是否还有其他我需要设置的超时,或者是否有任何原因导致上述设置不生效?
编辑:curl_easy_perform 的返回值为 CURLE_OPERATION_TIMEDOUT
I'm using libcurl to communicate with Twitter and Identi.ca. Everything works perfectly as long as my connection isn't busy. But if I'm downloading a large file, the curl requests timeout after 5 seconds.
I've set the following options on the curl handle:
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 15);
and they make no difference, curl_easy_perform()
always returns after 5 seconds. The CURLINFO_RESPONSE_CODE
and CURLINFO_HTTP_CONNECTCODE
values are always both zero.
Any ideas? Are there any other timeouts I need to set, or is there any reason why the above don't take effect?
EDIT: The return value of curl_easy_perform is CURLE_OPERATION_TIMEDOUT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说这是因为以下两个原因之一:
你没有在这里向我们展示完整的程序,所以你在其他地方有一个设置的超时选项来指示 libcurl 超时。
您的 libcurl 版本有一个错误,导致其行为异常。您没有说明您正在使用哪个平台上的 libcurl 版本。
要获得真正好的帮助,请提供针对公共 URL 重复问题的完整源代码。
I'd say it is because one out of two reasons:
You don't show us the complete program here so you have a set timeout option somewhere else that instructs libcurl to timeout.
Your libcurl version has a bug that makes it misbehave. You didn't say which libcurl version on what platform you're using.
To get really good help, provide a complete source code that repeats the problem against a public URL.
独立的curl程序是否成功下载文件?如果没有,服务器端可能有 5 秒的请求超时限制。
您应该仍然可以分块下载文件。首先抓取 HEAD 并拉出文件的大小,然后使用以下选项拉出文件的每个块:
一旦获得所有片段,将它们连接在一起,您就应该拥有完整的文件。
Does the standalone curl program successfully download the file? If not there might be a 5 second request timeout restriction server-side.
You should still be able to download the file in chunks. First grab the HEAD and pull the size of the file, then pull each chunk of the file using the following options:
Once you have all the pieces, concatenate them together and you should have your complete file.