Using the PHP Function Curl
PHP supports the libcURL library (and extension) which allows you to communicate with remote servers using a variety of protocols such as HTTP/HTTPS, FTP, LDAP, SCP and TELNET. You can use cURL to retrieve data from web services and APIs, or to extract it from web pages and crawlers.
To start working with cURL you need to initialize a cURL session by calling the curl_init function. After that you can define the various options you want to use with the curl_setopt function and execute your actual request with the curl_exec function. This will return the response content as a string which you can then parse with the curl_get_var and curl_set_var functions or pass to another application for further processing such as to generate HTML, JSON or XML.
You can also set options to control the behavior of Curl such as the CURLOPT_MAXREDIRS option which defines the maximum number of redirections that will be followed before the request is halted. This is useful to prevent infinite loops in some web applications. The CURLOPT_SSLVERSION option specifies which SSL version (2 or 3) to use for the connection. You can also specify the timeout limit for the request with the CURLOPT_TIMEOUT option which sets the max time in seconds for the connection.
You can also configure some logging options with the curl_log_level and curl_log_format options which log the level of detail you want in the output from the library. Finally, you can set some error handling options with the curl_error_handler and curl_error_logger options.