PHP 忒聊
綴豖
ヶ輛
XII. CURL, Client URL Library Functions
賡庄
PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
These functions have been added in PHP 4.0.2.
剒⑴
In order to use the CURL functions you need to install the CURL package. PHP requires that you use CURL 7.0.2-beta or higher. PHP will not work with any version of CURL below version 7.0.2-beta. From PHP version 4.2.3 you will atleast need CURL version 7.9.0 or higher.
假蚾
To use PHP's CURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use CURL for url streams --with-curlwrappers.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libeay32.dll and ssleay32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)
啎隅砱都講
蚕衾涴虳都講岆蚕蜆孺桯耀輸隅砱腔ㄛ秪森硐衄婓蜆孺桯耀輸掩晤祒善 PHP 笢ㄛ麼氪婓堍俴奀掩雄怓樓婥綴ㄛ涴虳都講符衄虴﹝
毓瞰
Once you've compiled PHP with CURL support, you can begin using the CURL functions. The basic idea behind the CURL functions is that you initialize a CURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the CURL functions to fetch the example.com homepage into a file:
瞰赽 1. Using PHP's CURL module to fetch the example.com homepage
?php $ch = curl_init ("http://www.example.com/"); $fp = fopen ("example_homepage.txt", "w"); curl_setopt ($ch, CURLOPT_FILE, $fp); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_exec ($ch); curl_close ($ch); fclose ($fp);?
醴翹 curl_close -- Close a CURL session curl_errno -- Return an integer containing the last error number curl_error -- Return a string containing the last error for the current session curl_exec -- Perform a CURL session curl_getinfo -- Get information regarding a specific transfer curl_init -- Initialize a CURL session curl_setopt -- Set an option for a CURL transfer curl_version -- Return the current CURL version
綴豖
れ萸
ヶ輛
crack_opendict
奻珨撰
curl_close