cURL which plays an important role in automating the tasks involving interaction between many web sites.
cURL (Client for URLs) is free and open software that compiles and runs under a wide variety of operating systems.
It is available as cURL command line tool or as libcurl library.
It is useful to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE)
cURL offers lot of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume and much more.
cURL is powered by libcurl for all transfer-related features. libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported and fast.
Libcurl is most probably the most portable, most powerful and most often used C-based multi-platform file transfer library on this planet – be it open source or commercial.
Using cURL you can:
- Implement payment gateways’ payment notification scripts.
- Download and upload files from remote servers.
- Login to other websites and access members only sections.
Once you’ve compiled PHP with cURL support, you can begin using the cURL functions.
You can find below the cURL related functions in php.
- curl_close — Close a cURL session
- curl_copy_handle — Copy a cURL handle along with all of its preferences
- curl_errno — Return the last error number
- curl_error — Return a string containing the last error for the current session
- curl_exec — Perform a cURL session
- curl_getinfo — Get information regarding a specific transfer
- curl_init — Initialize a cURL session
- curl_multi_add_handle — Add a normal cURL handle to a cURL multi handle
- curl_multi_close — Close a set of cURL handles
- curl_multi_exec — Run the sub-connections of the current cURL handle
- curl_multi_getcontent — Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
- curl_multi_info_read — Get information about the current transfers
- curl_multi_init — Returns a new cURL multi handle
- curl_multi_remove_handle — Remove a multi handle from a set of cURL handles
- curl_multi_select — Wait for activity on any curl_multi connection
- curl_setopt_array — Set multiple options for a cURL transfer
- curl_setopt — Set an option for a cURL transfer
- curl_version — Gets cURL version information
The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to fetch qualitypointtech.com homepage into a file.
<?php $ch = curl_init("http://www.qualitypointtech.com/"); $fp = fopen("qualitypoint_homepage.txt", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?>
You can play this Game to learn these cURL functions interestingly.
You can find here some of the applications written in PHP/CURL