我有以下设置:
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_TIMEOUT, 30);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
但是当请求被发送到当前没有响应的服务器时,curl会在1秒内返回答案。我不明白为什么会这样,因为我已经将CURLOPT_CONNECTTIMEOUT设置为30,这应该意味着卷曲轮胎连接到服务器30秒。我需要curl尝试连接30秒,这不是CURLOPT_CONNECTTIMEOUT应该做的,还是有某种误解?
这是print_r(curl_getinfo($ handle),true)返回的内容:
(
[url] => http://server.url
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.045
[namelookup_time] => 0.016
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] =>
)
答案 0 :(得分:1)
在我看来,这意味着有一个连接被远程站点关闭(中止)。服务器拒绝您的连接,因此无需等待任何事情。 BTW:connection_timeout是一个告诉curl等待多长时间才停止尝试访问远程主机的设置。 - Mo.sch 13小时前