Salvador Dali Salvador Dali - 2 years ago 239
PHP Question

PHP cUrl vs file_get_contents

Here is a question.
How these 2 pieces of code differ when accessing REST API?

$result = file_get_contents('');

$ch = curl_init('');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

because they both produce the same result, judging by:


Answer Source

file_get_contents() is a simple screwdriver. Great for simple GET requests where the header, HTTP request method, timeout, cookiejar, redirects, and other important things do not matter.

fopen() with a stream context or cURL with setopt are powerdrills with every bit and option you can think of.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download