php基于curl重写file_get_contents函数实例

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php基于curl重写file_get_contents函数实例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP基于curl重写file_get_contents函数分享给大家供大家参考,具体如下:

file_get_contents在连接不上的时候会提示Connection refused,有时候会带来不便;另外,curl的性能比file_get_contents高,所以用curl重写file_get_contents

<PRe class="brush:PHp;"> 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,CURLOPT_TIMEOUT,0); $buffer = curl_exec($ch); curl_close($ch); if ($buffer === false || empty($buffer)) { $ret = ""; } else { $ret = $buffer; } return $ret; }

脚本宝典总结

以上是脚本宝典为你收集整理的php基于curl重写file_get_contents函数实例全部内容,希望文章能够帮你解决php基于curl重写file_get_contents函数实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。