手机
当前位置:查字典教程网 >编程开发 >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页面缓存ob系列函数介绍

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

PHP curl使用实例

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

PHP curl伪造IP地址和header信息代码实例

一个目录遍历函数

php正则preg_replace_callback函数用法实例

php实现递归抓取网页类实例

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

php curl 上传文件代码实例

精品推荐
分类导航