php基于curl重寫file_get_contents函數(shù)實例
本文實例講述了php基于curl重寫file_get_contents函數(shù)。分享給大家供大家參考,具體如下:
file_get_contents在連接不上的時候會提示Connection refused,有時候會帶來不便;另外,curl的性能比file_get_contents高,所以用curl重寫file_get_contents
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相關內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結》、《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結》、《PHP常用遍歷算法與技巧總結》、《PHP數(shù)據(jù)結構與算法教程》、《php程序設計算法總結》、《PHP數(shù)學運算技巧總結》、《php正則表達式用法總結》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
- PHP CURL或file_get_contents獲取網(wǎng)頁標題的代碼及兩者效率的穩(wěn)定性問題
- php中file_get_contents與curl性能比較分析
- php采用file_get_contents代替使用curl實例
- 深入file_get_contents與curl函數(shù)的詳解
- 探討file_get_contents與curl效率及穩(wěn)定性的分析
- 比file_get_contents穩(wěn)定的curl_get_contents分享
- php中使用Curl、socket、file_get_contents三種方法POST提交數(shù)據(jù)
- PHP curl 或 file_get_contents 獲取需要授權頁面的方法
相關文章
phpmyadmin里面導入sql語句格式的大量數(shù)據(jù)的方法
phpmyadmin里面導入sql語句格式的大量數(shù)據(jù)的方法2010-06-06