note 86488 added to function.headers-sent
| From: | yesmarklapointe at hotmail dot com | Date: | Wed, 22 Oct 2008 01:07:46 +0000 |
| Subject: | note 86488 added to function.headers-sent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145557@lists.php.net to get a copy of this message | ||
I was having trouble getting my mind around the concepts involved. Here is my dilemma and the
conclusion I reached in case recounting them can help others:
I am using WAMPserver: PHP 5.2.6, and Apache 2.2.8 on Windows XP SP3. If it matters to your
duplication,
I found two php.ini files in WAMPserver where output_buffering had been set to 4096. I changed them
to OFF for this testing.
Here is how you can replicate what I am experiencing: With IE 7.0 go to Tools ... Display
ieHTTPheaders ... and run the following script repeatedly and watch what happens:
<?php
header( 'Expires: Mon, 26 Jul 1998 05:00:00 GMT' );
//var_dump(headers_sent());
//print("whatever");
//flush();
//echo "whatever";
var_dump(headers_sent());
?>
Result: the final var_dump of the headers_sent() function will
always return FALSE unless any one or more of the commented lines above it are uncommented.
Uncommenting the statements allows an output to be sent to the user not just to their browser, after
which the final var_dump will return TRUE. What I found confusing was that the ieHTTPheaders tool
shows that the header is being sent to the user's browser even when all the output lines are
commented out. So why does headers_sent() return FALSE in this case? Because you can keep sending
other headers. The headers_sent function is meant to alert one to when no further headers can be
sent. My testing shows it does not return true unless some other output is also sent after the
header, thereby signaling that "Headers have been sent and concluded with user output. NOW you
can't send any more headers."
Someone else worked his way through this problem in a (false) bug report: http://bugs.php.net/bug.php?id=30264
Here is the relevant part of the reply from the pro:
"When you use compression the entire page is buffered in memory, until end of the request.
Consequently you can send headers at any time because no data is being actually sent to user when
you print it. Until PHP actually decides to send any page output to the user you can still send
additional headers which is why the headers_sent() function is returning false. It will return true,
indicating that headers have been sent only at a time when output began going to the user and you
no longer can send any additional headers."
So in summary, my point is that there is a difference between headers being sent only to the browser
(which can be followed by other headers) vs. headers being sent and concluded by output for the
user. The function should have been given a more clear name like headers_concluded().
----
Server IP: 69.147.83.197
Probable Submitter: 72.223.11.42
----
Manual Page -- http://www.php.net/manual/en/function.headers-sent.php
Edit -- https://master.php.net/note/edit/86488
Del: integrated -- https://master.php.net/note/delete/86488/integrated
Del: useless -- https://master.php.net/note/delete/86488/useless
Del: bad code -- https://master.php.net/note/delete/86488/bad+code
Del: spam -- https://master.php.net/note/delete/86488/spam
Del: non-english -- https://master.php.net/note/delete/86488/non-english
Del: in docs -- https://master.php.net/note/delete/86488/in+docs
Del: other reasons-- https://master.php.net/note/delete/86488
Reject -- https://master.php.net/note/reject/86488
Search -- https://master.php.net/manage/user-notes.php