PHP CURL函數(shù)庫第1/2頁
Jun 13, 2016 pm 12:25 PM
curl_close — 關(guān)閉一個(gè)curl會(huì)話
curl_copy_handle — 拷貝一個(gè)curl連接資源的所有內(nèi)容和參數(shù)
curl_errno — 返回一個(gè)包含當(dāng)前會(huì)話錯(cuò)誤信息的數(shù)字編號(hào)
curl_error — 返回一個(gè)包含當(dāng)前會(huì)話錯(cuò)誤信息的字符串
curl_exec — 執(zhí)行一個(gè)curl會(huì)話
curl_getinfo — 獲取一個(gè)curl連接資源句柄的信息
curl_init — 初始化一個(gè)curl會(huì)話
curl_multi_add_handle — 向curl批處理會(huì)話中添加單獨(dú)的curl句柄資源
curl_multi_close — 關(guān)閉一個(gè)批處理句柄資源
curl_multi_exec — 解析一個(gè)curl批處理句柄
curl_multi_getcontent — 返回獲取的輸出的文本流
curl_multi_info_read — 獲取當(dāng)前解析的curl的相關(guān)傳輸信息
curl_multi_init — 初始化一個(gè)curl批處理句柄資源
curl_multi_remove_handle — 移除curl批處理句柄資源中的某個(gè)句柄資源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以數(shù)組的形式為一個(gè)curl設(shè)置會(huì)話參數(shù)
curl_setopt — 為一個(gè)curl設(shè)置會(huì)話參數(shù)
curl_version — 獲取curl相關(guān)的版本信息
curl_init()函數(shù)的作用初始化一個(gè)curl會(huì)話,curl_init()函數(shù)唯一的一個(gè)參數(shù)是可選的,表示一個(gè)url地址。
curl_exec()函數(shù)的作用是執(zhí)行一個(gè)curl會(huì)話,唯一的參數(shù)是curl_init()函數(shù)返回的句柄。
curl_close()函數(shù)的作用是關(guān)閉一個(gè)curl會(huì)話,唯一的參數(shù)是curl_init()函數(shù)返回的句柄。
$ch = curl_init("http://www.baidu.com/");
curl_exec($ch);
curl_close($ch);
?>
curl_version()函數(shù)的作用是獲取curl相關(guān)的版本信息,curl_version()函數(shù)有一個(gè)參數(shù),不清楚是做什么的
print_r(curl_version())
?>
curl_getinfo()函數(shù)的作用是獲取一個(gè)curl連接資源句柄的信息,curl_getinfo()函數(shù)有兩個(gè)參數(shù),第一個(gè)參數(shù)是curl的資源句柄,第二個(gè)參數(shù)是下面一些常量:
$ch = curl_init("http://www.baidu.com/");
print_r(curl_getinfo($ch));
?>
可選的常量包括:
CURLINFO_EFFECTIVE_URL
最后一個(gè)有效的url地址
CURLINFO_HTTP_CODE
最后一個(gè)收到的HTTP代碼
CURLINFO_FILETIME
遠(yuǎn)程獲取文檔的時(shí)間,如果無法獲取,則返回值為“-1”
CURLINFO_TOTAL_TIME
最后一次傳輸所消耗的時(shí)間
CURLINFO_NAMELOOKUP_TIME
名稱解析所消耗的時(shí)間
CURLINFO_CONNECT_TIME
建立連接所消耗的時(shí)間
CURLINFO_PRETRANSFER_TIME
從建立連接到準(zhǔn)備傳輸所使用的時(shí)間
CURLINFO_STARTTRANSFER_TIME
從建立連接到傳輸開始所使用的時(shí)間
CURLINFO_REDIRECT_TIME
在事務(wù)傳輸開始前重定向所使用的時(shí)間
CURLINFO_SIZE_UPLOAD
上傳數(shù)據(jù)量的總值
CURLINFO_SIZE_DOWNLOAD
下載數(shù)據(jù)量的總值
CURLINFO_SPEED_DOWNLOAD
平均下載速度
CURLINFO_SPEED_UPLOAD
平均上傳速度
CURLINFO_HEADER_SIZE
header部分的大小
CURLINFO_HEADER_OUT
發(fā)送請(qǐng)求的字符串
CURLINFO_REQUEST_SIZE
在HTTP請(qǐng)求中有問題的請(qǐng)求的大小
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD
從Content-Length: field中讀取的下載內(nèi)容長度
CURLINFO_CONTENT_LENGTH_UPLOAD
上傳內(nèi)容大小的說明
CURLINFO_CONTENT_TYPE
下載內(nèi)容的“Content-type”值,NULL表示服務(wù)器沒有發(fā)送有效的“Content-Type: header”
curl_setopt()函數(shù)的作用是為一個(gè)curl設(shè)置會(huì)話參數(shù)。curl_setopt_array()函數(shù)的作用是以數(shù)組的形式為一個(gè)curl設(shè)置會(huì)話參數(shù)。
$ch = curl_init();
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
$options = array(
CURLOPT_URL => 'http://www.baidu.com/',
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
可設(shè)置的參數(shù)有:
CURLOPT_AUTOREFERER
自動(dòng)設(shè)置header中的referer信息
CURLOPT_BINARYTRANSFER
在啟用CURLOPT_RETURNTRANSFER時(shí)候?qū)@取數(shù)據(jù)返回
CURLOPT_COOKIESESSION
啟用時(shí)curl會(huì)僅僅傳遞一個(gè)session cookie,忽略其他的cookie,默認(rèn)狀況下curl會(huì)將所有的cookie返回給服務(wù)端。session cookie是指那些用來判斷服務(wù)器端的session是否有效而存在的cookie。
CURLOPT_CRLF
啟用時(shí)將Unix的換行符轉(zhuǎn)換成回車換行符。
CURLOPT_DNS_USE_GLOBAL_CACHE
啟用時(shí)會(huì)啟用一個(gè)全局的DNS緩存,此項(xiàng)為線程安全的,并且默認(rèn)為true。
CURLOPT_FAILONERROR
顯示HTTP狀態(tài)碼,默認(rèn)行為是忽略編號(hào)小于等于400的HTTP信息
CURLOPT_FILETIME
啟用時(shí)會(huì)嘗試修改遠(yuǎn)程文檔中的信息。結(jié)果信息會(huì)通過curl_getinfo()函數(shù)的CURLINFO_FILETIME選項(xiàng)返回。
CURLOPT_FOLLOWLOCATION
啟用時(shí)會(huì)將服務(wù)器服務(wù)器返回的“Location:”放在header中遞歸的返回給服務(wù)器,使用CURLOPT_MAXREDIRS可以限定遞歸返回的數(shù)量。
CURLOPT_FORBID_REUSE
在完成交互以后強(qiáng)迫斷開連接,不能重用。
CURLOPT_FRESH_CONNECT
強(qiáng)制獲取一個(gè)新的連接,替代緩存中的連接。
CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.
CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.
CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it.
CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.
CURLOPT_HEADER
啟用時(shí)會(huì)將頭文件的信息作為數(shù)據(jù)流輸出。
CURLOPT_HTTPGET
啟用時(shí)會(huì)設(shè)置HTTP的method為GET,因?yàn)镚ET是默認(rèn)是,所以只在被修改的情況下使用。
CURLOPT_HTTPPROXYTUNNEL
啟用時(shí)會(huì)通過HTTP代理來傳輸。
CURLOPT_MUTE
講curl函數(shù)中所有修改過的參數(shù)恢復(fù)默認(rèn)值。
CURLOPT_NETRC
在連接建立以后,訪問~/.netrc文件獲取用戶名和密碼信息連接遠(yuǎn)程站點(diǎn)。
CURLOPT_NOBODY
啟用時(shí)將不對(duì)HTML中的body部分進(jìn)行輸出。
CURLOPT_NOPROGRESS
啟用時(shí)關(guān)閉curl傳輸?shù)倪M(jìn)度條,此項(xiàng)的默認(rèn)設(shè)置為true
CURLOPT_NOSIGNAL
啟用時(shí)忽略所有的curl傳遞給php進(jìn)行的信號(hào)。在SAPI多線程傳輸時(shí)此項(xiàng)被默認(rèn)打開。
CURLOPT_POST
啟用時(shí)會(huì)發(fā)送一個(gè)常規(guī)的POST請(qǐng)求,類型為:application/x-www-form-urlencoded,就像表單提交的一樣。
CURLOPT_PUT
啟用時(shí)允許HTTP發(fā)送文件,必須同時(shí)設(shè)置CURLOPT_INFILE和CURLOPT_INFILESIZE
CURLOPT_RETURNTRANSFER
講curl_exec()獲取的信息以文件流的形式返回,而不是直接輸出。
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2). TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.
CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH
在使用CURLOPT_FOLLOWLOCATION產(chǎn)生的header中的多個(gè)locations中持續(xù)追加用戶名和密碼信息,即使域名已發(fā)生改變。
CURLOPT_UPLOAD
啟用時(shí)允許文件傳輸
CURLOPT_VERBOSE
啟用時(shí)會(huì)匯報(bào)所有的信息,存放在STDERR或指定的CURLOPT_STDERR中
CURLOPT_BUFFERSIZE
每次獲取的數(shù)據(jù)中讀入緩存的大小,這個(gè)值每次都會(huì)被填滿。
CURLOPT_CLOSEPOLICY
不是CURLCLOSEPOLICY_LEAST_RECENTLY_USED就是CURLCLOSEPOLICY_OLDEST,還存在另外三個(gè),但是curl暫時(shí)還不支持。.
CURLOPT_CONNECTTIMEOUT
在發(fā)起連接前等待的時(shí)間,如果設(shè)置為0,則不等待。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

The key steps to install PHP on Windows include: 1. Download the appropriate PHP version and decompress it. It is recommended to use ThreadSafe version with Apache or NonThreadSafe version with Nginx; 2. Configure the php.ini file and rename php.ini-development or php.ini-production to php.ini; 3. Add the PHP path to the system environment variable Path for command line use; 4. Test whether PHP is installed successfully, execute php-v through the command line and run the built-in server to test the parsing capabilities; 5. If you use Apache, you need to configure P in httpd.conf

The basic syntax of PHP includes four key points: 1. The PHP tag must be ended, and the use of complete tags is recommended; 2. Echo and print are commonly used for output content, among which echo supports multiple parameters and is more efficient; 3. The annotation methods include //, # and //, to improve code readability; 4. Each statement must end with a semicolon, and spaces and line breaks do not affect execution but affect readability. Mastering these basic rules can help write clear and stable PHP code.

The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.

How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

The "undefinedindex" error occurs because a key that does not exist in the array is accessed. Solutions include: 1. Use isset() to check whether the key exists, which is suitable for processing user input; 2. Use array_key_exists() to determine whether the key is set, and it can be recognized even if the value is null; 3. Use the empty merge operator?? to set the default value to avoid directly accessing undefined keys; in addition, you need to pay attention to common problems such as the spelling of form field names, the database result is empty, the array unpacking is not verified, the child keys are not checked in foreach, and the session_start() is not called.
