Can someone explain the differences of file_get_contents vs guzzle vs curl?

1

2

I've been getting data from api websites by using file_get_contents or curl, but I never knew whats the difference from them. They seem to have the same results, but now there is Guzzle for php. What is the difference from all these 3? Why would one choose one over the other?

Patoshi パトシ

Posted 2016-05-26T22:17:35.850

Reputation: 1 687

Question was closed 2017-04-10T12:00:43.313

Answers

0

file_get_contents is in-built into PHP and can be used without installing any dependencies. It's fine for simple requests (even though you can do POST requests, too), but e.g. retrieving response status details and headers is cumbersome.

cURL is a library and command line tool to do network requests - not only HTTP but also IMAP, SMTP and others. It requires the PHP curl extension, which may not be installed on the machine your code is running. It has a procedural interface.

guzzle is a PHP userland library that provides a object based interface for HTTP requests. You need to install it in any case to use it.

cweiske

Posted 2016-05-26T22:17:35.850

Reputation: 1 010