Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to file_get_contents?

$xml_file = file_get_contents(SITE_PATH . 'cms/data.php'); 

The problem is that a server has URL file-access disabled. I cannot enable it, its a hosting thing.

So the question is this. The data.php file generates xml code.

How can I execute this and get the xml data without doing the above method?

Is it possible?

like image 898
JasonS Avatar asked Oct 20 '10 15:10

JasonS


People also ask

Is cURL faster than file_get_contents?

file_get_contents() is slightly faster than cURL.

How can I get the content of a file in PHP?

The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.

What is the difference between file_get_contents ($ file and file_get_contents ($ file?

They both read an entire file, but file reads the file into an array, while file_get_contents reads it into a string.

Does file_get_contents cache?

Short answer: No. file_get_contents is basically just a shortcut for fopen, fread, fclose etc - so I imagine opening a file pointer and freading it isn't cached.


1 Answers

Use cURL. This function is an alternative to file_get_contents.

function url_get_contents ($Url) {     if (!function_exists('curl_init')){          die('CURL is not installed!');     }     $ch = curl_init();     curl_setopt($ch, CURLOPT_URL, $Url);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     $output = curl_exec($ch);     curl_close($ch);     return $output; } 
like image 172
Pelle Avatar answered Sep 18 '22 19:09

Pelle