What is cURL?
cURL is a module in PHP with we can use libcurl. The libcurl is a library that is used in PHP to create connection and communicate with various kinds of different servers which may have different type of protocols. cURl provide us various pre-built functions like – curl_init(), curl_setopt(), curl_exec(), curl_close().
Limitations of cURL:
- cURL does not support any recursive download logic.
- cURL requires extra options to download.
- Does not provide us with asynchronus and synchronus requests.
Example: These are the request made by using cURL.
<?php> // Get cURL resource $curl = curl_init(); // Set some options curl_setopt($ch, CURLOPT_POST, curl_setopt($ch, CURLOPT_POST, false) ; curl_setopt($ch, CURLOPT_RETURNTANSFER, false) ; $result = curl_exec($ch); curl_close($ch); ?> |
Output:

What is Guzzle?
Guzzle is a Microframework (abstraction layer) that is a PHP HTTP client due to which the HTTP request is sent easily and it is trivial to integrate with web services. Guzzle can be used with any HTTP handler like cURL, socket, PHP’s stream wrapper. Guzzle by default uses cURL as Http handler.
Why use Guzzle Instead of cURL in PHP?
- It provides easy user interface.
- Guzzle can use various kinds of HTTP clients .
- It allows us with the facility of asynchronus and synchronus requests.
- Guzzle has built-in unit testing support which makes it easier to write unit tests for app and mock the http requests.
Example: These are the request made by using Guzzle.
<?php use GuzzleHTTP\Client; require '>>/vendor/autoload.php'; $client = new Client([ 'timeout' => 2.0 ]); $response = $client->request('GET', 'ip'); echo $response->getStatusCOde(), "<br>"; $body = $response->getBody(); echo $body->getContents(), "<br>"; echo "<pre>"; print_r(get_class_methods($body)); echo "</pre>"; echo "<pre>"; print_r(get_class_methods($response)); echo "</pre>"; ?> |
Output:

Recommended Posts:
- Why to use .html instead of .htm extension?
- How to use cURL via a proxy ?
- JavaScript SyntaxError - Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
- PHP | cURL
- How to get cookies from curl into a variable in PHP ?
- How to Install php-curl in Ubuntu ?
- How to enable cURL in PHP?
- Difference between file_get_contents and cURL in PHP
- curl command in Linux with Examples
- How to find where the URL will redirected using cURL?
- Why require_once() function is so bad to use in PHP ?
- Creating custom domain name instead of localhost in Ubuntu
- How to tab space instead of multiple non-breaking spaces (nbsp)?
- How to make Bootstrap popover appear/disappear on hover instead of click?
- What is the best way to include CSS file? Why use @import?
- Why do we use $rootScope.$broadcast in AngularJS?
- Why card images use data-src (not src) for image in Bootstrap 4 ?
- Why use Question mark in TypeScript variable ?
- What is Web API and why we use it ?
- Why we use then() method in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

