PHP/cURL is a library that helps you to make HTTP requests in PHP using libcurl.

PHP supports libcurl, a library created by Daniel Stenberg.

In order to use this functions you need to install the  libcurl

To understand we will have to know about following terms

  1. cURL
  2. libcurl
  3. PHP/cURL

cURL is a command line tool for receiving or sending files using URL syntax

libcurl  is a library that allows us to connect and communicate to different types of servers with different types of protocols.

It  is supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols.sit i also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies.

It  helps the PHP programms to make use of libcurl to make HTTP request .

Now you have an idea of the different terms used.

Basically the following steps are need to follow to use in php.

Initialize->set options->fatch/send->close

  1. Initialize a session
  2. Set options for the session
  3. Execute the action or get/send data from/to server
  4. Close the session

Example: To fetch the homepage

    1. Initialize a curl session


$ch = curl_init(“”);

    1. setting options


$fp = fopen(“abc.txt”, “w”); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0);

    1. Execute



    1. Close


curl_close($ch); fclose($fp); ?>

We can do more task with curl like curl_error() , curl_setopt(), curl_getinfo(), curl_version() etc.

  1. curl_error(): to check the errors based on the return value(bool) of the curl_exec().
  2. curl_setopt() : Set an option for a transfer.
  3. curl_getinfo() :  Get information regarding a specific transfer
  4. curl_version() : Gets version information

There are lots of options are available. You can take a look at the manual for more and detailed information.

Thank you for reading this article,

If any thing is wrong in the article please do let us know in the comment section.
We will be very happy to hear that.

Leave comment

Your email address will not be published. Required fields are marked with *.