The cURL stands for ‘Client for URLs’ which has two library libcurl, curl and PHP/cURL.
libcurl library allows you to connect and communicate to many different types of servers with many different types of protocols. The libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. The libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user & password authentication.
curl is a command line tool for getting or sending files using URL syntax.
PHP/cURL is PHP module which makes it possible for PHP programs to use libcurl.
What is cURL in php?
The cURL is a PHP based library and a command line tool that helps you transfer data over FTP, TPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. The cURL is used to get contents form another webpage in php.
How to use cURL in php?
We can use cURL in php program using below cURL functions.
- curl_init() : This function will initialize a new session and return a cURL handle $ch.
- curl_setopt($ch, option, value) : This function set value for an option for a cURL session identified by the ch parameter. It return page contents if you set CURLOPT_RETURNTRANSFER option value is 1. If CURLOPT_RETURNTRANSFER set 0 then no output will be returned. CURLOPT_URL option pass URL as a parameter for your targeted server website address where you want to get web contents.
- curl_exec($ch) : This function execute the curl session given by $ch. It returns output.
- curl_close($ch) : close curl session and free up system resources.
We can understand cURL using below example.