note 92865 added to function.headers-list

From: Date: Wed, 12 Aug 2009 13:13:20 +0000
Subject: note 92865 added to function.headers-list
Groups: php.notes 
Request: Send a blank email to php-notes+get-159366@lists.php.net to get a copy of this message
In response to the gimme_headers() and get_headers() methods below: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html As described in 9.4 - "HEAD": The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. So use HEAD instead because it SHOULD be much faster than GET... For this behaviour it is much simpler to create a stream for the additional context param in all file functions: <?php header('Content-Type:text/plain'); $HTTP_HEAD = stream_context_create(array('http' => array('method' => 'HEAD'))); $fp = fopen('http://www.php.net', 'r', false, $HTTP_HEAD); $headers = stream_get_meta_data($fp); fclose($fp); echo(var_export($headers)); ?> which should give something like this: <?php array ( 'wrapper_data' => array ( 0 => 'HTTP/1.1 200 OK', 1 => 'Date: Wed, 12 Aug 2009 13:00:32 GMT', 2 => 'Server: Apache/1.3.41 (Unix) PHP/5.2.9RC3-dev', 3 => 'X-Powered-By: PHP/5.2.9RC3-dev', 4 => 'Last-Modified: Wed, 12 Aug 2009 11:50:23 GMT', 5 => 'Content-language: en', 6 => 'Set-Cookie: expires=Wed, 19-Aug-2009 13:00:32 GMT; path=/; domain=.php.net', 7 => 'Connection: close', 8 => 'Content-Type: text/html;charset=utf-8', ), 'wrapper_type' => 'http', 'stream_type' => 'tcp_socket', 'mode' => 'r+', 'unread_bytes' => 0, 'seekable' => false, 'uri' => 'http://www.php.net', 'timed_out' => false, 'blocked' => true, 'eof' => false, ) ?> ---- Server IP: 217.160.72.57 Probable Submitter: 85.8.70.161 ---- Manual Page -- http://www.php.net/manual/en/function.headers-list.php Edit -- https://master.php.net/note/edit/92865 Del: integrated -- https://master.php.net/note/delete/92865/integrated Del: useless -- https://master.php.net/note/delete/92865/useless Del: bad code -- https://master.php.net/note/delete/92865/bad+code Del: spam -- https://master.php.net/note/delete/92865/spam Del: non-english -- https://master.php.net/note/delete/92865/non-english Del: in docs -- https://master.php.net/note/delete/92865/in+docs Del: other reasons-- https://master.php.net/note/delete/92865 Reject -- https://master.php.net/note/reject/92865 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159366) next »