php基于curl重寫file_get_contents函數(shù)實(shí)例
本文實(shí)例講述了php基于curl重寫file_get_contents函數(shù)。分享給大家供大家參考,具體如下:
file_get_contents在連接不上的時(shí)候會(huì)提示Connection refused,有時(shí)候會(huì)帶來不便;另外,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;
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- PHP CURL或file_get_contents獲取網(wǎng)頁標(biāo)題的代碼及兩者效率的穩(wěn)定性問題
- php中file_get_contents與curl性能比較分析
- php采用file_get_contents代替使用curl實(shí)例
- 深入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 獲取需要授權(quán)頁面的方法
相關(guān)文章
phpmyadmin里面導(dǎo)入sql語句格式的大量數(shù)據(jù)的方法
phpmyadmin里面導(dǎo)入sql語句格式的大量數(shù)據(jù)的方法2010-06-06
PHP實(shí)現(xiàn)對(duì)xml的增刪改查操作案例分析
這篇文章主要介紹了PHP實(shí)現(xiàn)對(duì)xml的增刪改查操作,結(jié)合具體案例形式分析了php針對(duì)xml格式文件的增刪改查操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-05-05
Thinkphp框架開發(fā)移動(dòng)端接口(2)
這篇文章主要介紹了thinkphp框架開發(fā)移動(dòng)端接口的第2種方法,實(shí)現(xiàn)移動(dòng)端訪問自動(dòng)切換移動(dòng)主題模板,從而實(shí)現(xiàn)偽app訪問,感興趣的小伙伴們可以參考一下2016-08-08

