View Full Version : File Get Contents

Tony M
05-25-2011, 05:32 PM
I am using php file_get_contents to get an external file to My website....
But file_get_contents might use more system resources
I am trying to use CURL instead...

My php code (that uses file_get_contents) is:


$url = "http://www.example.com/mail.php";

$file = file_get_contents($url);

// and replace 'mail' to 'tony' ...

But how can I replace this file_get_contents code to CURL (I want a code that reduce system resources usage and not increasing it...)?

Any Suggestion Will Be Helpful :thumbsup:

05-25-2011, 06:39 PM
Something like this(not tested):

$url = "http://www.example.com/mail.php";

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// grab URL and pass it to the browser
$file = curl_exec($ch);

// close cURL resource, and free up system resources

$file = str_replace('mail', 'tony', $file);

file_put_contents('mail2.php', $txt);

There are lots of examples in the docs (http://php.net/curl_exec).