PHP.nl

curl_getinfo

curl_getinfo

Get information regarding a specific transfer

mixed **curl_getinfo** CurlHandle $handle  $option

Gets information about the last transfer.

option One of the constants. CURLINFO_*

If is given, returns its value. Otherwise, returns an associative array with the following elements (which correspond to ), or false on failure:

Note that private data is not included in the associative array and must be retrieved individually with the option. option``option- "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 the is set by a previous call to ) CURLINFO_HEADER_OUT``curl_setopt
  • "posttransfer_time_us" (Available as of PHP 8.4.0 and cURL 8.10.0)

CURLINFO_PRIVATE

Voorbeeld: 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";
}
?>

Voorbeeld: example with 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";
  }
}
?>

Opmerking: > 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.