curl-getinfo
curl_getinfo
Get information regarding a specific transfer
ENTITY
mixed
curl_getinfo
CurlHandle
handle
int
null
option
ENTITY
Gets information about the last transfer.
ENTITY
option
One of the CURLINFO_* constants.
ENTITY
If option is given, returns its value. Otherwise, returns an associative array with the following elements (which correspond to option), or ENTITY on failure:
-
"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"
-
"certinfo"
-
"primary_ip"
-
"primary_port"
-
"local_ip"
-
"local_port"
-
"redirect_url"
-
"request_header" (This is only set if
CURLINFO_HEADER_OUTis set by a previous call tocurl_setopt) -
"posttransfer_time_us" (Available as of PHP 8.4.0 and cURL 8.10.0)
Note that private data is not included in the associative array and must be retrieved individually with the CURLINFO_PRIVATE option.
ENTITY
| ENTITY | ENTITY |
|---|---|
| 8.4.0 | Introduced CURLINFO_POSTTRANSFER_TIME_T constant and posttransfer_time_us (Curl 8.10.0 or later). |
| 8.3.0 | Introduced CURLINFO_CAINFO and CURLINFO_CAPATH. |
| 8.2.0 | Introduced CURLINFO_PROXY_ERROR, CURLINFO_REFERER, CURLINFO_RETRY_AFTER. |
| 8.0.0 | option is nullable now; previously, the default was 0. |
| 7.3.0 | Introduced CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, CURLINFO_CONTENT_LENGTH_UPLOAD_T, CURLINFO_HTTP_VERSION, CURLINFO_PROTOCOL, CURLINFO_PROXY_SSL_VERIFYRESULT, CURLINFO_SCHEME, CURLINFO_SIZE_DOWNLOAD_T, CURLINFO_SIZE_UPLOAD_T, CURLINFO_SPEED_DOWNLOAD_T, CURLINFO_SPEED_UPLOAD_T, CURLINFO_APPCONNECT_TIME_T, CURLINFO_CONNECT_TIME_T, CURLINFO_FILETIME_T, CURLINFO_NAMELOOKUP_TIME_T, CURLINFO_PRETRANSFER_TIME_T, CURLINFO_REDIRECT_TIME_T, CURLINFO_STARTTRANSFER_TIME_T, CURLINFO_TOTAL_TIME_T. |
ENTITY
curl_getinfo example
<?php
// Create a cURL handle
$ch = curl_init('http://www.example.com/');
// Execute
curl_exec($ch);
// Check if any error occurred
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
echo 'Took ', $info['total_time'], ' seconds to send a request to ', $info['url'], "\n";
}
?>
curl_getinfo example with option parameter
<?php
// Create a cURL handle
$ch = curl_init('http://www.example.com/');
// Execute
curl_exec($ch);
// Check HTTP status code
if (!curl_errno($ch)) {
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 200: # OK
break;
default:
echo 'Unexpected HTTP code: ', $http_code, "\n";
}
}
?>
ENTITY
Information gathered by this function is kept if the handle is re-used. This means that unless a statistic is overridden internally by this function, the previous info is returned.
谢谢你的反馈!