Simply, cURL is a command line tool for getting or sending files using URL syntax. It supports a range of common Internet protocols, including HTTP, FTP, SCP, SFTP, TFTP, TELNET, FILE, IMAP, POP3, SMTP and RTSP, etc. The command is designed to work without user interaction.
Usage:-
Basic use of cURL involves simply typing curl at the command line, followed by the URL of the output to retrieve.
To retrieve the google.com homepage, type:
curl www.google.com
What is PHP/CURL?
The module for PHP that makes it possible for PHP programs to access curl-functions from within PHP.
How to verify cURL is working correctly?.
cURL does have very powerfull functions which inturn not used properly may leads to complete breakdown of your server. Because of this most of the hosting companies disable some of these dangerous functions. But for a PHP Programmer cURL is an essential tool and must requires basic functionality atleast. It is very easy to check the PHP/cURL is working normal.
Steps:-
1. Create a php file “check_cURL.php” with following content using any of your favourite editor.
<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
‘http://news.google.com/news?hl=en&topic=t&output=rss’);
/**
* Create a new file
*/
$fp = fopen(‘rss.xml’, ‘w’);
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>
2. Execute the “check_cURL.php” script (I just run “php -q check_cURL.php” from the terminal)
3. Check the output file “rss.xml”. If the file contains data, we can conclude curl is working fine.
How does this script works:-
The check_cURL.php is simple php script which when called connects to the url specified(Google in our example) and download its source code. The script then writes its output to downloaded content to the output file(rss.xml in our example).