Bri*_*ana 1 php proxy curl http libcurl
我正在学习 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;
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么它永远不会超时吗?我只想等待 25 秒,但由于任何原因(例如代理已死)而无法等待,那么它应该超时。