获取请求标头通过file_get_contents()发送

When using file_get_contents() to request an external URL, how can I find out what headers I've sent, or alternatively what headers I am about to send? I'm basically looking for a request counterpart for $http_response_header or anything else I can use to extract the same data.

I know I get to set headers myself with stream_context_create(array ('http' => array ('header' => $header))), but I want to see what headers are actually being sent in the end, including default ones.

If you need a consistent header to go out with each file_get_contents request, use the stream contexts like this example:

<?php

// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en
" .
              "Cookie: foo=bar
"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);

?>

Src: http://php.net/manual/en/function.file-get-contents.php