curl重写php file_get_contents

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

curl重写php 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;
}
curl重写php file_get_contents

 

curl重写php file_get_contents,布布扣,bubuko.com

curl重写php file_get_contents

上一篇:MVVM架构~knockoutjs系列之验证信息自定义输出~续


下一篇:Nodejs安装express提示不是内部或外部命令