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;
}
更多關(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è)計算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
- PHP CURL或file_get_contents獲取網(wǎng)頁標(biāo)題的代碼及兩者效率的穩(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 獲取需要授權(quán)頁面的方法
相關(guān)文章
PHP使用PDO創(chuàng)建MySQL數(shù)據(jù)庫、表及插入多條數(shù)據(jù)操作示例
這篇文章主要介紹了PHP使用PDO創(chuàng)建MySQL數(shù)據(jù)庫、表及插入多條數(shù)據(jù)操作,結(jié)合實例形式總結(jié)分析了php基于pdo的mysql數(shù)據(jù)庫創(chuàng)建、數(shù)據(jù)表創(chuàng)建以及多條數(shù)據(jù)插入操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2019-05-05
PHP實現(xiàn)上傳文件并存進(jìn)數(shù)據(jù)庫的方法
這篇文章主要介紹了PHP實現(xiàn)上傳文件并存進(jìn)數(shù)據(jù)庫的方法,涉及php文件上傳所涉及的文件與表單操作及數(shù)據(jù)庫操作相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-07-07
php簡單定時執(zhí)行任務(wù)的實現(xiàn)方法
這篇文章主要介紹了php簡單定時執(zhí)行任務(wù)的實現(xiàn)方法,涉及curl及sleep等操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-02-02

