一,http请求超时时间
可能出现的场景:
1,curl进程运行了一个世纪还木结束,curl的时候设置了超时时间 --connect-timeout 1000
2,operation timed out after 1000 milliseconds with 0 bytes received
3,connect() timed out!
wget对超时时间, 是有分阶段的, 比如说请求的超时, 传输的超时,同样HTTP请求有两个超时时间:一个是连接超时时间,另一个是数据传输的最大允许时间,出现问题就要看是哪个超时时间出问题了。
curl命令行
连接超时时间用 --connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定,时间是毫秒
例如:
curl --connect-timeout 10 -m 20 "http://***"
连接超时的话,出错提示形如:
curl: (28) connect() timed out!
数据传输的最大允许时间超时的话,出错提示形如:
curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received
使用PHP的curl_init
<?php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0);
//连接超时时间 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1000);
//数据传输的最大允许时间 curl_setopt($ch, CURLOPT_TIMEOUT, 1000); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch);
//使用curl_error($ch)查看错误的详情 var_dump(curl_error($ch));