如何用 Zend_Http_Client 替换 file_get_contents ?(编码差异等..)
应该替换的代码:
$url='http://google.com';$timeout=60;
$t = stream_context_create(array('http' => array('timeout' => $timeout)));
$content = @file_get_contents($url,0,$t);
我的解决方案:
$url='http://google.com';$timeout=60;
$client = new Zend_Http_Client($url, array('timeout' => $timeout));
$content=$client->request()->getBody();
请问你有更好的解决方案,我的解决方案有弱点吗?
编辑:改进的解决方案
function getResponse($url='http://google.com',$timeout=60){
$client = new Zend_Http_Client($url, array('timeout' => $timeout));
if($content->isError()) {
return null;
}
return $content->getBody();
}
备注:更好的事件可以使用卷曲适配器,它的工作速度更快。
谢谢,约瑟夫