PHP cURL Functions


Overview

The libcurl library created by Daniel Stenberg, supported by PHP, allows you to connect and communicate with various types of 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 (this can also be done via PHP's FTP extension), HTTP form-based upload, proxies, cookies, and username + password authentication.

Methods for implementing 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 thelibcurlpackage.

PHP requires 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. As of PHP 4.3.0, you need to install libcurl 7.9.0 or higher. As of PHP 5.0.0, you need to install 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. In the include directory, there must be a folder named curl containing easy.h and curl.h. The lib folder should have a file named libcurl.a. For PHP 4.3.0, you can configure --with-curlwrappers to make cURL use URL streams.

Note: Win32 users note To use this module in the 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 two types of resources: cURL handles and cURL batch handles.



PHP cURL Functions

The following contains the 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 most recent error of the current session.
curl_escape() Returns an escaped string, performing URL encoding on 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 batch 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 text stream of the fetched output.
curl_multi_info_read() Gets the related transfer information of the currently parsed cURL.
curl_multi_init() Returns a new cURL batch handle.
curl_multi_remove_handle() Removes a handle resource from the curl batch handle resource.
curl_multi_select() Waits for all active connections in the cURL batch.
curl_multi_setopt() Sets a batch cURL transfer option.
curl_multi_strerror() Returns a string text describing the error code.
curl_pause() Pauses and resumes a connection.
curl_reset() Resets all options of the libcurl session handle.
curl_setopt_array() Batch sets options for a cURL transfer session.
curl_setopt() Sets a cURL transfer option.
curl_share_close() Closes a cURL shared handle.
curl_share_init() Initializes a cURL shared handle.
curl_share_setopt() Sets a cURL transfer option for a shared handle.
curl_strerror() Returns a string description of the error code.
curl_unescape() Decodes a URL-encoded string.
curl_version() Gets cURL version information.
Other Extensions