手机
当前位置:查字典教程网 >编程开发 >php教程 >php基于curl重写file_get_contents函数实例
php基于curl重写file_get_contents函数实例
摘要:本文实例讲述了php基于curl重写file_get_contents函数。分享给大家供大家参考,具体如下:file_get_content...

本文实例讲述了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重写file_get_contents函数实例】相关文章:

php实现的mongodb操作类实例

php使用GD实现颜色渐变实例

PHP curl使用实例

PHP 反射(Reflection)使用实例

php实现简单的语法高亮函数实例分析

php线性表的入栈与出栈实例分析

php实现的简单日志写入函数

php curl请求信息和返回信息设置代码实例

php微信公众平台开发类实例

php基于curl扩展制作跨平台的restfule 接口

精品推荐
分类导航