php 方法笔记 比file_get_contents好

/*比file_get_contents稳定的多!$timeout为超时时间,单位是秒,默认为1s。*/
private function curl_get_contents($url,$timeout=1) {
$curlHandle = curl_init();
curl_setopt( $curlHandle, CURLOPT_URL, $url );
curl_setopt( $curlHandle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $curlHandle, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt( $curlHandle, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curlHandle, CURLOPT_TIMEOUT, $timeout );
$result = curl_exec( $curlHandle );
curl_close( $curlHandle );
return $result;
}

posted on 2015-03-20 22:01  kantlee  阅读(126)  评论(0编辑  收藏  举报

导航