时时商务社区
标题:
php基于curl重写file_get_contents函数实例
[打印本页]
作者:
yj1281
时间:
2018-2-14 05:30
本文实例讲述了php基于curl重写file_get_contents函数。分享给大家供大家参考,具体如下:
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相关内容感兴趣的读者可查看本站专题:《
php curl用法总结
》、《
PHP数组(Array)操作技巧大全
》、《
php排序算法总结
》、《
PHP常用遍历算法与技巧总结
》、《
PHP数据结构与算法教程
》、《
php程序设计算法总结
》、《
PHP数学运算技巧总结
》、《
php正则表达式用法总结
》、《
PHP运算与运算符用法总结
》、《
php字符串(string)用法总结
》及《
php常见数据库操作技巧汇总
》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
php中使用Curl、socket、file_get_contents三种方法POST提交数据
比file_get_contents稳定的curl_get_contents分享
探讨file_get_contents与curl效率及稳定性的分析
深入file_get_contents与curl函数的详解
php采用file_get_contents代替使用curl实例
php中file_get_contents与curl性能比较分析
PHP CURL或file_get_contents获取网页标题的代码及两者效率的稳定性问题
PHP curl 或 file_get_contents 获取需要授权页面的方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2