比file_get_contents稳定的curl_get_contents分享
分享一个实际在用的函数:
<div class="codetitle"><a style="CURSOR: pointer" data="72390" class="copybut" id="copybut72390" onclick="doCopy('code72390')"> 代码如下:
<div class="codebody" id="code72390">
/
比file_get_contents稳定的多!$timeout为超时时间,单位是秒,默认为1s。/
function curl_get_contents($url,$timeout=1) {
$curlHandle = curl_init();
curl_setopt( $curlHandle,CURLOPT_URL,$url );
curl_setopt( $curlHandle,CURLOPT_RETURNTRANSFER,1 );
curl_setopt( $curlHandle,CURLOPT_TIMEOUT,$timeout );
$result = curl_exec( $curlHandle );
curl_close( $curlHandle );
return $result;
}
$hx = curl_get_contents('//www.jb51.cc');