PHP curl_getinfo Function
(PHP 4 >= 4.0.4, PHP 5)
curl_getinfo — Get information regarding a specific cURL transfer
Description
mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )
Retrieve information about the last transfer.
Parameters
ch
A cURL handle returned by curl_init().
opt
This parameter can be one of the following constants:
CURLINFOEFFECTIVEURL - Last effective URL
CURLINFOHTTPCODE - Last received HTTP code
CURLINFO_FILETIME - Remote time of the retrieved document, -1 if it cannot be retrieved
CURLINFOTOTALTIME - Total transaction time in seconds for the last transfer
CURLINFONAMELOOKUPTIME - Time in seconds until name resolving was complete
CURLINFOCONNECTTIME - Time in seconds it took to establish the connection
CURLINFOPRETRANSFERTIME - Time in seconds from start until just before file transfer begins
CURLINFOSTARTTRANSFERTIME - Time in seconds until the first byte is about to be transferred
CURLINFOREDIRECTTIME - Time in seconds of all redirection steps before the final transaction was started
CURLINFOSIZEUPLOAD - Total number of bytes uploaded
CURLINFOSIZEDOWNLOAD - Total number of bytes downloaded
CURLINFOSPEEDDOWNLOAD - Average download speed
CURLINFOSPEEDUPLOAD - Average upload speed
CURLINFOHEADERSIZE - Total size of headers
CURLINFOHEADEROUT - The request string sent
CURLINFOREQUESTSIZE - Total size of issued requests, currently only for HTTP requests
CURLINFOSSLVERIFYRESULT - Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFOCONTENTLENGTH_DOWNLOAD - Content-Length of the download, read from the Content-Length: field
CURLINFOCONTENTLENGTH_UPLOAD - Specified size of upload data sent
CURLINFOCONTENTTYPE - Content-Type of the requested document, NULL indicates server did not send a valid Content-Type header
Return Values
If opt is given, returns its value as a string. Otherwise, returns an associative array with the following elements (which correspond to opt):
"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 | Introduced CURLINFO_HEADER_OUT. |
Examples
<?php
// Create a cURL handle
$ch = curl_init('http://www.yahoo.com/');
// Execute
curl_exec($ch);
// Check for errors
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);
?>