(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
curl_getinfo — Get information regarding a specific transfer
curl_getinfo(CurlHandle $handle, ?int $option = null): mixed
Gets information about the last transfer.
handle A cURL handle returned by curl_init().
option One of the CURLINFO_* constants.
If option is given, returns its value. Otherwise, returns an associative array with the following elements (which correspond to option), or false on failure:
CURLINFO_HEADER_OUT is set by a previous call to curl_setopt()) CURLINFO_PRIVATE option. | Version | Description |
|---|---|
| 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 | handle expects a CurlHandle instance now; previously, a resource was expected. |
| 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. |
Example #1 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";
}
?> Example #2 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";
}
}
?> Note:
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.
© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.curl-getinfo.php