php curl默认链接超时时间是多少
3 回答
侃侃无极
TA贡献2051条经验 获得超10个赞
curl代码如下
123456789101112131415161718192021222324 /**
* curl操作
* @param unknown_type $pURL
* @param unknown_type $pPostData
* @return unknown
*/
public
static
function
getURLContent(
$pURL
,
$pPostData
=
''
) {
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$pURL
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$ch
, CURLOPT_CONNECTTIMEOUT, 1);
// 连接超时(秒)
curl_setopt(
$ch
, CURLOPT_TIMEOUT, 3);
// 执行超时(秒)
if
(
$pPostData
) {
curl_setopt(
$ch
, CURLOPT_POST, 1);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$pPostData
);
}
$out_put
= curl_exec(
$ch
);
curl_close(
$ch
);
return
$out_put
;
}
理论是可以设置无限长的时间,但实际操作中不可能这样做,可根据实际情况设置
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); // 连接超时(秒)
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // 执行超时(秒)
白衣非少年
TA贡献1155条经验 获得超0个赞
global $g_handle;
if (empty($g_handle)) $ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FRESH_CONNECT => false,
CURLOPT_FORBID_REUSE => false,
CURLOPT_TIMEOUT => $timeout
);
curl_setopt_array($g_handle, $options);
$ret = curl_exec($g_handle);
return $ret;
}
- 3 回答
- 0 关注
- 2890 浏览
添加回答
举报
0/150
提交
取消