PHP curl_getinfo Function
(PHP 4 >= 4.0.4, PHP 5)
curl_getinfo — Get information about a cURL connection resource handle
Description
mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )
Gets information about the last transfer.
Parameters
ch
The cURL handle returned by curl_init().
opt
This parameter can be one of the following constants:
- CURLINFO_EFFECTIVE_URL- The last valid URL address
- CURLINFO_HTTP_CODE- The last received HTTP code
- CURLINFO_FILETIME- Time to fetch the remote document; returns "-1" if it cannot be fetched
- CURLINFO_TOTAL_TIME- Time consumed by the last transfer
- CURLINFO_NAMELOOKUP_TIME- Time consumed by name resolution
- CURLINFO_CONNECT_TIME- Time consumed to establish a connection
- CURLINFO_PRETRANSFER_TIME- Time used from establishing the connection to preparing for the transfer
- CURLINFO_STARTTRANSFER_TIME- Time used from establishing the connection to starting the transfer
- CURLINFO_REDIRECT_TIME- Time used for redirects before the transfer begins
- CURLINFO_SIZE_UPLOAD- Total amount of uploaded data
- CURLINFO_SIZE_DOWNLOAD- Total amount of downloaded data
- CURLINFO_SPEED_DOWNLOAD- Average download speed
- CURLINFO_SPEED_UPLOAD- Average upload speed
- CURLINFO_HEADER_SIZE- Size of the header part
- CURLINFO_HEADER_OUT- The string of the request sent
- CURLINFO_REQUEST_SIZE- Size of the problematic request in the HTTP request
- CURLINFO_SSL_VERIFYRESULT- By settingCURLOPT_SSL_VERIFYPEER- The result of the SSL certificate verification request returned
- CURLINFO_CONTENT_LENGTH_DOWNLOAD- FromContent-Length:- Download content length read from the field
- CURLINFO_CONTENT_LENGTH_UPLOAD- Description of the upload content size
- CURLINFO_CONTENT_TYPE- The downloaded content'sContent-Type:- value; NULL indicates the server did not send a validContent-Type: header
Return Values
If opt is set, returns its value as a string. Otherwise, returns an associative array containing the following elements (which correspond to opt respectively):
- "url"
- "content_type"
- "http_code"
- "header_size"
- "request_size"
- "filetime"
- "ssl_verify_result"
- "redirect_count"
- "total_time"
- "namelookup_time"
- "connect_time"
- "pretransfer_time"
- "size_upload"
- "size_download"
- "speed_download"
- "speed_upload"
- "download_content_length"
- "upload_content_length"
- "starttransfer_time"
- "redirect_time"
Changelog
| Version | Description |
|---|---|
| 5.1.3 | IntroducedCURLINFO_HEADER_OUT.
|
Examples
<?php
// 创建一个cURL句柄
$ch = curl_init('http://www.yahoo.com/');
// 执行
curl_exec($ch);
// 检查是否有错误发生
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
// Close handle
curl_close($ch);
?>
Other Extensions
PHP cURL Reference Manual