PHP cURL



Overview

The libcurl library created by Daniel Stenberg, supported by PHP, allows you to connect and communicate with a variety of servers using various types of protocols.

libcurl currently supports 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 through PHP's FTP extension), HTTP form-based upload, proxy, cookies and username + password authentication.

How to use cURL to implement Get and Post requests in PHP

These functions were introduced in PHP 4.0.2.



Requirements

In order to use PHP’s cURL function, you need to install the » libcurl package.

PHP requires libcurl 7.0.2-beta or higher. To use cURL with PHP 4.2.3, you need to install libcurl version 7.9.0 or higher. Starting with PHP 4.3.0 you need to install libcurl version 7.9.0 or higher. Starting with PHP 5.0.0 you need to install version 7.10.5 or higher of libcurl.



Installation

To use PHP's cURL support you must add the --with-curl[=DIR] option when compiling PHP. DIR contains lib and include directory path. There must be a folder named curl that contains easy.h and curl.h in the include directory. There should be a file named libcurl.a in the lib folder. 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 a Windows environment, libeay32.dll and ssleay32.dll must be placed in the directory included in the PATH environment variable. Do not use libcurl.dll from the cURL website.


Resource type

This extension defines 2 resources: cURL handle and cURL batch handle.



PHP cURL functions

The following contains a list of PHP cURL functions:

Function Description
curl_close()Close a cURL session.
curl_copy_handle()Copy a cURL handle and all its options.
curl_errno()Returns the last error number.
curl_error()Returns a string that protects the most recent error in the current session.
curl_escape()Returns the escape string, URL encoding the given string.
curl_exec()Execute a cURL session.
curl_file_create()Create a CURLFile object.
curl_getinfo()Get information about a cURL connection resource handle.
curl_init()Initialize a cURL session.
curl_multi_add_handle()Add individual curl handles to the curl batch session.
curl_multi_close()Close a group of cURL handles.
curl_multi_exec() Runs a sub-connection of the current cURL handle.
curl_multi_getcontent()If CURLOPT_RETURNTRANSFER is set, returns the text stream of the obtained output.
curl_multi_info_read()Get the relevant transmission information of the currently parsed cURL.
curl_multi_init()Returns a new cURL batch handle.
curl_multi_remove_handle()Remove a handle resource in the curl batch handle resource.
curl_multi_select()Wait for all active connections in the cURL batch.
curl_multi_setopt()Set a batch cURL transfer option.
curl_multi_strerror()Returns a string text describing the error code.
curl_pause()Pause and resume the connection.
curl_reset()Resets all options of libcurl's session handle.
curl_setopt_array() Set options in batches for cURL transfer sessions.
curl_setopt()Set a cURL transfer option.
curl_share_close()Close the cURL shared handle.
curl_share_init()Initialize the cURL share handle.
curl_share_setopt()Sets the cURL transfer options for a shared handle.
curl_strerror()Returns a string description of the error code.
curl_unescape()Decode the URL-encoded string.
curl_version()Get cURL version information.