PHP-powered libcurl library created by Daniel Stenberg 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 accomplished through PHP's FTP extension), HTTP form-based upload, proxy, cookies, and username and password authentication.
How to use cURL to implement Get and Post requests in PHP (recommended learning: PHP video tutorial)
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 that 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.
For example, let’s take Baidu, the famous “test network connection” website, as an example to try curl
<?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "baidu.com"); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); //echo output echo $output; // close curl resource to free up system resources curl_close($ch); ?>
The above is the detailed content of Is curl built-in with PHP?. For more information, please follow other related articles on the PHP Chinese website!