Skip to content
Advertisement

PHP cURL vs file_get_contents

How do these two pieces of code differ when accessing a REST API?

JavaScript

and

JavaScript

They both produce the same result, judging by

JavaScript

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement