php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29162 HEAD request script terminates on non-header output
Submitted: 2004-07-14 22:00 UTC Modified: 2005-04-26 17:17 UTC
From: php-bugs at carldunham dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.7 OS: Linux (Gentoo 1.4)
Private report: No CVE-ID: None
 [2004-07-14 22:00 UTC] php-bugs at carldunham dot com
Description:
------------
It seems that a script executing in response to a HEAD 
request will terminate when non-header output is 
generated. This can lead to different behavior in HEAD vs 
GET, which may not be desirable. Other bug reports 
(http://bugs.php.net/bug.php?id=15693) have indicated that 
the entire script executes, which does not seem to be the 
case. 
 
I was unable to find documentation of what is the intended 
behavior, although I would vote for having the script 
complete no matter the method, as working around cases 
where that is not desirable is easier: 
 
if ($_SERVER['REQUEST_METHOD'] == 'HEAD') exit(); 
 
at the top of a script, vs. 
 
if ($_SERVER['REQUEST_METHOD'] != 'HEAD') { 
   // do outputty things 
} 
// do non-outputty things 
 
sprinkled throughout the code. 

Reproduce code:
---------------
<?php

$fp = fopen('/tmp/test-head.out', 'a');

fwrite($fp, "Method = " . $_SERVER['REQUEST_METHOD'] . "\n");

echo "hello";

fwrite($fp, "POST: " . print_r($_POST, true) . "\n");
fwrite($fp, "GET: " . print_r($_GET, true) . "\n\n");

fclose($fp);


?>



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-15 02:42 UTC] iliaa@php.net
This is expected behavior, it should be documented. 
 [2005-04-26 17:17 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Documented by REQUEST_METHOD in reserved.variables.server: (didn't find better place for it)
"PHP script is terminated after sending headers (it means after producing any output without output buffering) if request method was HEAD."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 16:00:03 2025 UTC