作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在了解 CURLOPT_CONNECTTIMEOUT,我在这个测试中使用了 25 秒超时设置的代理,但它从未超时,我不知道为什么。这是我的简单代码
$proxy="124.206.54.251:3128";
$timeout = 25;
$url = "http://google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );
$returned_msg = curl_exec($ch);
$error = curl_error($ch);
$info= curl_getinfo($ch);
curl_close($ch);
echo "<br>".$returned_msg."<br>".$info['total_time']."<br>".$error;
有人能告诉我为什么它永远不会超时吗?我只想等待 25 秒,但由于任何原因无法等待,例如代理已死,那么它应该超时。
最佳答案
CURLOPT_CONNECTTIMEOUT 仅设置连接所需时间的超时。如果您想限制允许整个请求花费的时间量,请改用 CURLOPT_TIMEOUT。
关于php - CURLOPT_CONNECTTIMEOUT 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35516623/
我正在了解 CURLOPT_CONNECTTIMEOUT,我在这个测试中使用了 25 秒超时设置的代理,但它从未超时,我不知道为什么。这是我的简单代码 $proxy="124.206.54.251:3
PHP 有这两个与超时相关的选项:CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT。 PHP 站点上的描述有点含糊。有什么区别? 举一个真实世界的例子:假设您通过 cU
我想在检测到 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT 时进行检测、捕获并执行某些操作。 我该怎么做? 我有以下标题: public static $userA
我是一名优秀的程序员,十分优秀!