How replace file_get_contents with Zend_Http_Client ?(differnce in encoding etc..)
code that should be replaced:
$url='http://google.com';$timeout=60;
$t = stream_context_create(array('http' => array('timeout' => $timeout)));
$content = @file_get_contents($url,0,$t);
My Solution:
$url='http://google.com';$timeout=60;
$client = new Zend_Http_Client($url, array('timeout' => $timeout));
$content=$client->request()->getBody();
please do you have better solution, does my solution have weak parts?
Edit:Improved solution
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();
}
Remark: event better can be use of curl adapter that doing work much faster.
Thanks, Yosef