Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
DIV class = reference>
XI. CURL, client URL library function
PHP supports libcurl (you can use different protocols to connect to and communicate with different servers )., Libcurl currently supports http, https, ftp, gopher, telnet, dict, file, and ldap protocols. Libcurl also supports HTTPS Certificate authorization, http post, http put, FTP upload (of course, you can also use PHP ftp extension), HTTP Basic form Upload, proxy, cookies, and user authentication.
To use the CURL function, you need to install the CURL package. PHP requires you to use CURL 7.0.2-beta or later. If the CURL version is earlier than 7.0.2-beta, PHP will not work.
To support php curl, you must re-compile PHP with the -- with-curl [= DIR] parameter (DIR is the directory containing the library and header files ).
These functions are added in PHP 4.0.2.
Once you compile PHP with CURL support, you can use the curl function. The basic idea is: you use the curl_init () function to initialize the CURL session, and then you can set all your options to run through the curl_exec () function. Finally, you can use curl_close () function to end your session. The following is an example: put the PHP homepage back into a file.
Example 1. Use the php curl module to retrieve the PHP homepage
$ Ch = curl_init ("http://www.php.net /");
$ Fp = fopen ("php_homepage.txt", "w ");
Curl_setopt ($ ch, CURLOPT_FILE, $ fp );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_exec ($ ch );
Curl_close ($ ch );
Fclose ($ fp );
Curl_init-initialize a CURL session
Curl_setopt-set an option for CURL calls
Curl_exec-execute a CURL session
Curl_close-close a CURL session
Curl_version-returns the current CURL version
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.