gpt4 book ai didi

php - CURLOPT_CONNECTTIMEOUT 不工作

转载 作者:可可西里 更新时间:2023-11-01 17:07:29 30 4
gpt4 key购买 nike

我正在了解 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com