PHP cURL Functions
Overview
PHP supports the libcurl library, created by Daniel Stenberg, which allows you to connect and communicate with various servers using various types of protocols.
libcurl currently supports the http, https, ftp, gopher, telnet, dict, file and ldap protocols. libcurl also supports HTTPS authentication, HTTP POST, HTTP PUT, FTP upload (which can also be done via PHP's FTP extension), HTTP form-based upload, proxies, cookies, and username+password authentication.
How to implement Get and Post requests using cURL in PHP
These functions were introduced in PHP 4.0.2.
Requirements
To use PHP's cURL functions, you need to install libcurl the package.
PHP needs libcurl 7.0.2-beta or higher. To use cURL in PHP 4.2.3, you need to install libcurl 7.9.0 or higher. Starting from PHP 4.3.0 you need libcurl 7.9.0 or higher. Starting from PHP 5.0.0 you need libcurl 7.10.5 or higher.
Installation
To use PHP's cURL support you must add the --with-curl[=DIR] option when compiling PHP, where DIR is the directory path containing lib and include. Inside the include directory there must be a folder named curl containing easy.h and curl.h. The lib folder should contain a file named libcurl.a. For PHP 4.3.0 you can configure --with-curlwrappers to make cURL use URL streams.
Note: Windows users, to use this module in a Windows environment, libeay32.dll and ssleay32.dll must be placed in a directory included in the PATH environment variable. Do not use the libcurl.dll from the cURL website.
Resource types
This extension defines 2 resources: a cURL handle and a cURL multi-handle.
PHP cURL Functions
The following is a list of PHP cURL functions:
| function | Description |
|---|---|
| curl_close() | Closes a cURL session. |
| curl_copy_handle() | Copies a cURL handle and all its options. |
| curl_errno() | Returns the last error number. |
| curl_error() | Returns a string containing the last error for the current session. |
| curl_escape() | Returns an escaped string, URL-encoding the given string. |
| curl_exec() | Executes a cURL session. |
| curl_file_create() | Creates a CURLFile object. |
| curl_getinfo() | Gets information about a cURL connection resource handle. |
| curl_init() | Initializes a cURL session. |
| curl_multi_add_handle() | Adds an individual curl handle to a curl multi session. |
| curl_multi_close() | Closes a set of cURL handles. |
| curl_multi_exec() | Runs the sub-connections of the current cURL handle. |
| curl_multi_getcontent() | If CURLOPT_RETURNTRANSFER is set, returns the fetched output as a string. |
| curl_multi_info_read() | Gets transfer information for the current resolved cURL. |
| curl_multi_init() | Returns a new cURL multi handle. |
| curl_multi_remove_handle() | Removes a handle resource from the curl multi handle resource. |
| curl_multi_select() | Waits for all active connections in the curl multi handle. |
| curl_multi_setopt() | Sets an option for a cURL multi transfer. |
| curl_multi_strerror() | Returns the string text describing an error code. |
| curl_pause() | Pauses and resumes connections. |
| curl_reset() | Resets all options of the libcurl session handle. |
| curl_setopt_array() | Sets options in bulk for a cURL transfer session. |
| curl_setopt() | Sets a cURL transfer option. |
| curl_share_close() | Closes a cURL share handle. |
| curl_share_init() | Initializes a cURL share handle. |
| curl_share_setopt() | Sets the cURL transfer options of a share handle. |
| curl_strerror() | Returns the string description of an error code. |
| curl_unescape() | Decodes a URL-encoded string. |
| curl_version() | Gets cURL version information. |