php curl默认链接超时时间是多少?

php curl默认链接超时时间是多少


温温酱
浏览 2891回答 3
3回答

侃侃无极

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); // 执行超时(秒)

白衣非少年

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;}
打开App,查看更多内容
随时随地看视频慕课网APP