How to use file_get_contents() (Dreamhost.com)
Written by Administrator   
Tuesday, 23 January 2007

DreamHost has disabled the PHP option allow_url_fopen.

Not working  file_get_contents() . The CURL library provides a feature-rich alternative.

Example:

Use:

$file_contents = 
file_get_contents('http://dreamhost.com/');
 // display file 
 echo $file_contents; 

Use:

$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://dreamhost.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;

 

 or even better, hides the cURL stuff in a function...
// function to replace file_get_contents()
function file_get_the_contents($url) {
$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
Last Updated ( Tuesday, 30 January 2007 )