php curl默認鏈接超時時間是多少
php curl默認鏈接超時時間是多少?
溫溫醬
2019-05-27 22:06:30
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;
}
舉報