php curl重写file_get_contents php基于curl重写file_get_contents函数实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php curl重写file_get_contents php基于curl重写file_get_contents函数实例

ifeixiang   2021-03-22 我要评论
想了解php基于curl重写file_get_contents函数实例的相关内容吗,ifeixiang在本文为您仔细讲解php curl重写file_get_contents的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,curl,重写,file_get_contents,下面大家一起来学习吧。

本文实例讲述了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程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们