PHP curl_getinfo Function
(PHP 4 >= 4.0.4, PHP 5)
curl_getinfo β Get information about a cURL transfer
Description
mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )
Gets information regarding the last transfer.
Parameters
ch
A cURL handle returned by curl_init().
opt
This parameter may be one of the following constants:
- CURLINFO_EFFECTIVE_URL - Last effective URL
- CURLINFO_HTTP_CODE - Last received HTTP code
- CURLINFO_FILETIME - Remote time of the retrieved document, if -1 is returned the time was not successfully retrieved
- CURLINFO_TOTAL_TIME - Total time of the previous transfer
- CURLINFO_NAMELOOKUP_TIME - Time from start until name resolving was completed
- CURLINFO_CONNECT_TIME - Time from start until the remote host or proxy was connected
- CURLINFO_PRETRANSFER_TIME - Time from start until just before the transfer begins
- CURLINFO_STARTTRANSFER_TIME - Time from start until just before the first byte is received
- CURLINFO_REDIRECT_TIME - Time taken for all redirect operations before the transaction starts
- CURLINFO_SIZE_UPLOAD - Total amount of bytes uploaded
- CURLINFO_SIZE_DOWNLOAD - Total amount of bytes downloaded
- CURLINFO_SPEED_DOWNLOAD - Average download speed
- CURLINFO_SPEED_UPLOAD - Average upload speed
- CURLINFO_HEADER_SIZE - Size of headers
- CURLINFO_HEADER_OUT - The request string sent
- CURLINFO_REQUEST_SIZE - Size of the request in bytes
- CURLINFO_SSL_VERIFYRESULT - Result of SSL certificate verification requested by setting CURLOPT_SSL_VERIFYPEER
- CURLINFO_CONTENT_LENGTH_DOWNLOAD - Content length from the _Content-Length:_ field
- CURLINFO_CONTENT_LENGTH_UPLOAD - Upload content size
- CURLINFO_CONTENT_TYPE - Content-Type of the downloaded object, NULL indicates no _Content-Type:_ header was sent by the server
Return Values
If opt is given, returns its value as a string. Otherwise, returns an associative array with the following elements:
- "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 | Added CURLINFO_HEADER_OUT. |
Example
<?php
// Create a cURL handle
$ch = curl_init('http://www.yahoo.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'];
}
// Close handle
curl_close($ch);
?>
YouTip