views:

41

answers:

2

Does php native function get_headers() downloads all the content, or stops downloading after getting header?

+2  A: 

I can't test it myself right now, but according to this comment in the manual:

If anyone is curious, as I was, this function does not send a HEAD verb. Instead it sends a GET. Which in my case is not ideal because I need a quick way to get a HTTP status (200, 404, etc.) The problem with GET is that, for cases such as mine, I do not want all the overhead with the data that comes back.

indeed the full response body is transmitted every time.

Take it with a grain of salt, but seeing as the manual doesn't mention the HEAD method, I think this is correct.

Pekka
A: 

get_headers only graps header part of the response, and drops the connection.

I enter interactive mode using php -a issued the command :

php > print_r( get_headers('http://ftp.linux.org.tr/ubuntu-releases//maverick/ubuntu-10.10-desktop-i386.iso'));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 30 Oct 2010 23:33:12 GMT
[2] => Server: Apache/2.2.13 (FreeBSD)
[3] => Last-Modified: Thu, 07 Oct 2010 16:25:11 GMT
[4] => ETag: "c7e78fe-2b528000-492095688a7c0"
[5] => Accept-Ranges: bytes
[6] => Content-Length: 726827008
[7] => Connection: close
[8] => Content-Type: application/octet-stream
)

This took less than 1 sec. Since chrome says It took 1 day to download ubuntu, compared to 1sec response of get_headers, it should be gather only headers.

nerkn