I tried to open an external url. It works fine in my local server. But when i moved to live server it showing time out error.
When i replaced the url by a url in the same domain ,it works fine.
allow_url_fopen is ON in the server.
<?php
if ($fp = fopen('https://www.google.com/', 'r')) {
$content = '';
// keep reading until there's nothing left
while ($line = fread($fp, 1024)) {
$content .= $line;
}
echo $content;
echo 'do something with the content here';
// ...
} else {
echo 'an error occured when trying to open the specified url';
}
?>
Updated
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://www.google.co.in/');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)){
print "Nothing returned from url..<p>";
}
else{
print $buffer;
}
I tried cURL too. It returns "Nothing returned from url..". But it works fine in my local and demo server.