1

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

nerkn
  • 1,867
  • 1
  • 20
  • 36
  • well without knowing how your function is build or what it does it's pretty impossible to give you any answers at all – Breezer Oct 30 '10 at 17:05
  • get_headers — Fetches all the headers sent by the server in response to a HTTP request. source: http://de.php.net/manual/en/function.get-headers.php RTFM – ITroubs Oct 30 '10 at 17:08
  • @Breezer thank you pointing typo – nerkn Oct 30 '10 at 17:08
  • @ITroubs how does this answer his question, which is effectively whether `get_headers()` makes a HEAD request or not? As far as I can see, that is not clear from the manual. – Pekka Oct 30 '10 at 17:09
  • that's why i just wrote a coment. btw in nearly all cases the manual with it's comments were pretty helpfull and no further questioning in any kind of forum was needed – ITroubs Oct 30 '10 at 18:48
  • Here's the get_headers source from PHP 5.3.3, in C: http://gist.github.com/655895 – Yahel Oct 30 '10 at 23:50

2 Answers2

1

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
  • 442,112
  • 142
  • 972
  • 1,088
0

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
  • 1,867
  • 1
  • 20
  • 36