CURL Introduction
curl is a file transfer tool that uses URL syntax to work in command line mode.
It supports many protocols: FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP.
Curl also supports HTTPS authentication, HTTP POST method, HTTP PUT method, FTP upload, kerberos authentication, HTTP upload, proxy server, cookies, username/password authentication, download file resumable upload, upload file resumable upload, http Proxy tunneling, it even supports IPv6, socks5 proxy server, uploading files to FTP server through http proxy server, etc. It is very powerful.
It can do all the functions of Internet Ant and FlashGet under Windows operating system. To be precise, curl supports file upload and download, so it is a comprehensive transmission tool. However, according to tradition, users are accustomed to calling curl a download tool.
curl in PHP
There is also a set of functions for curl operations in php. These functions start with curl_. For details, you can check the php manual
Because it is relatively efficient and does not require server-specific configuration support, it can be used in ordinary virtual hosts. file_get_contents() is slightly less efficient and commonly used in failure situations. curl() is very efficient and supports multi-threading. However, you need to enable the curl extension.
The following are the steps to enable curl extension:
1. Copy the three files php_curl.dll, libeay32.dll, and ssleay32.dll under the PHP folder to system32; (depending on the extension dll directory settings)
2. Remove the semicolon in extension=php_curl.dll in php.ini (c:WINDOWS directory);
3. Restart apache or IIS.
Basic steps to set up a cURL request in PHP:
Initialization
Set variables
Execute and get the results
Release cURL handle
// 1. Initialization
$ch = curl_init();
// 2. Set options, including URL
curl_setopt($ch, CURLOPT_URL, "http://www.nettuts.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
// 3. Execute and obtain the HTML document content
$output = curl_exec($ch);
// 4. Release curl handle
curl_close($ch);