卷曲连接超时不起作用
我使用 CURL 连接到多个 xml feed 并在页面加载时处理它们。不幸的是,每隔一段时间,页面就不会响应,我的脚本也会停止。这是我正在使用的代码的示例。我将超时设置为 1,但这似乎不起作用。然后,我将超时设置为 0.0001,只是为了今天进行测试,但它仍然提取 xml 提要。你们对于如何在脚本永远运行时强制curl超时有什么想法吗?
foreach($urls as $k => $v) {
$curl[$k] = curl_init();
curl_setopt($curl[$k], CURLOPT_URL, $v);
curl_setopt($curl[$k], CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl[$k], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl[$k],CURLOPT_CONNECTTIMEOUT, 1);
I'm using CURL to connect to multiple xml feeds and process them when the page loads. Unfortunately, every once in awhile a page won't be responsive and my script will stall as well. Here's an example of the code that I'm working with. I set the timeout to 1 but that doesn't appear to be working. I then set the timeout to 0.0001 just to test things today and it still pulled in xml feeds. Do you guys have any ideas on how to force curl to timeout when a script is taking forever.
foreach($urls as $k => $v) {
$curl[$k] = curl_init();
curl_setopt($curl[$k], CURLOPT_URL, $v);
curl_setopt($curl[$k], CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl[$k], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl[$k],CURLOPT_CONNECTTIMEOUT, 1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 Curl 库从 Apache 服务器下载文件。
downloadFileWithCurlLibrary 函数有两个输入。
FileUrl 是将从服务器下载的文件。
示例:www.abc.com/myfile.doc。
locFile 是要保存的目录和文件名。
示例:/home/projectx/myfile.doc。
i am using Curl library for download a file from Apache Server.
downloadFileWithCurlLibrary fonction has two inputs.
FileUrl is the file will download form server.
Example : www.abc.com/myfile.doc.
locFile is directory and file name you want to save.
Example:/home/projectx/myfile.doc.
curl 有两种不同的超时 - 请参阅
curl_setopt
手册页面:和 :
它们都有一个“毫秒”版本:分别是
CURLOPT_CONNECTTIMEOUT_MS
和CURLOPT_TIMEOUT_MS
。在您的情况下,您可能也想配置第二个:似乎花费时间的不是连接,而是服务器端提要的构建。
There are two different timeouts with curl -- see
curl_setopt
manual's page :And :
They both have a "millisecond" version :
CURLOPT_CONNECTTIMEOUT_MS
andCURLOPT_TIMEOUT_MS
, respectively.In your case, you might want to configure the second one too : what seems to take time is not the connection, but the construction of the feed on the server side.
查看 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT 之间的区别
See the difference between CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT