file_get_contentsをZend_Http_Clientに置き換える方法は?(エンコーディングの違いなど)
置き換える必要のあるコード:
$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();
}
備考:イベントは、はるかに高速に動作するcurlアダプターを使用することでより適切になります。
ありがとう、ヨセフ