YouTip LogoYouTip

Func Curl_Getinfo

PHP curl_getinfo Function .example { background-color: #f9f9f9; border: 1px solid #ddd; padding: 10px; margin: 10px 0; } .code { font-family: monospace; background-color: #f5f5f5; padding: 2px 5px; } .note { color: #666; font-style: italic; } .nav { margin-bottom: 20px; } .nav a { margin-right: 10px; } .breadcrumb { margin-bottom: 15px; } .breadcrumb a { margin-right: 5px; } .content { max-width: 900px; margin: 0 auto; padding: 20px; } h1 { color: #333; } h2 { color: #444; border-bottom: 1px solid #eee; padding-bottom: 5px; } table { border-collapse: collapse; width: 100%; margin: 15px 0; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } .prev-next { margin-top: 30px; display: flex; justify-content: space-between; } .prev-next a { text-decoration: none; color: #0066cc; }

PHP curl_getinfo Function

PHP cURL Reference Manual

(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);
?>

← Func Curl_InitFunc Curl_File_Create β†’