本文实例讲述了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基于curl重写file_get_contents函数实例内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!




