《PHP實例:php基于curl重寫file_get_contents函數實例》要點:
本文介紹了PHP實例:php基于curl重寫file_get_contents函數實例,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例講述了php基于curl重寫file_get_contents函數.分享給大家供大家參考,具體如下:
PHP編程file_get_contents在連接不上的時候會提示Connection refused,有時候會帶來不便;另外,curl的性能比file_get_contents高,所以用curl重寫file_get_contents
PHP編程
function _file_get_contents($s) {
$ret = "";
$ch = curl_init($s);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$buffer = curl_exec($ch);
curl_close($ch);
if ($buffer === false || empty($buffer)) {
$ret = "";
} else {
$ret = $buffer;
}
return $ret;
}
PHP編程更多關于PHP相關內容感興趣的讀者可查看本站專題:《php curl用法總結》、《PHP數組(Array)操作技巧大全》、《php排序算法總結》、《PHP常用遍歷算法與技巧總結》、《PHP數據結構與算法教程》、《php程序設計算法總結》、《PHP數學運算技巧總結》、《php正則表達式用法總結》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》及《php常見數據庫操作技巧匯總》
PHP編程希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2852.html