cURL (or "client for URLS") is a command-line tool for getting or sending files using URL syntax. It was first used in 2007 by Daniel Stenberg as a way to transfer files via protocols such as HTTP, HTTPS, FTP, Gopher, and many others, via a command-line interface. Since then, many more contributors has participated in further developing cURL, and the tool is used widely today. As an example, the following command is a basic way to retrieve a page from example.com
curl www.example.com
cURL defaults to displaying the output it retrieves to the standard output specified on the system (usually the terminal window). So running the command above would, on most systems, display the www.example.com source-code in the terminal window. cURL can write the output it retrieves to a file with the -o flag, thus:
curl -o example.html www.example.com
This will store the source code for www.example.com into a file named example.html. While retrieving output, cURL will display a progress-bar showing how much of the output has downloaded. Note however that cURL does not show a progress bar when preparing to display the output in the terminal window, since a progress-bar is likely to interfere with the display of the output. To download output to a file that has the same name as on the system it originates from, use the -O flag:
curl -O (URL)
PHP is one of the languages that provide full support for cURL. Luckily, PHP also enables you to use cURL without invoking the command line, making it much easier to use cURL while the server is executing. The example below demonstrates how to retrieve a page called example.com
<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, cURLOPT_FILE, $fp);
curl_setopt($ch, cURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>