#50276 [NEW]: PHP cache headers do NOT override server headers

2009-11-23 Thread vector dot thorn at gmail dot com
From: vector dot thorn at gmail dot com
Operating system: Fedora Linux
PHP version:  5.3.1
PHP Bug Type: Output Control
Bug description:  PHP cache headers do NOT override server headers

Description:

If this section is in your httpd.conf:

Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma


Then the cache headers here will not be used:

$expires = 60*60*24*365;
$size = filesize("{$client_directory}/{$_GET['did']}");
$last = filemtime("{$client_directory}/{$_GET['did']}");
header("Content-Length: ".$size,true);
header("Etag: ".md5($last),true);
header("Server: Ionisis.com",false);
header("Cache-Control: max-age={$expires}, public,no-transform",true);
header('Expires: ' . gmdate('D, d M Y H:i:s',($last+$expires)) . '
GMT',true);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last) . '
GMT',true);
header("Content-type: audio/example");
header("Content-Disposition: attachment; filename=\"{$_GET['did']}\"");
readfile("{$client_directory}/{$_GET['did']}");

and even if you remove that section, and these headers are sent, the
client is still not sending a "if-modified-since" header that can be
captured at the server level for the php level.

Firefox 3.5, Apache 2.2, PHP 5.3, Fedora Linux

Reproduce code:
---
Just copy that code, and paste it in an file called download.php, and set
it up so that it grabs an mp3 file, then beat your head into the desk for 2
days :D

Expected result:

I expected it to send the proper cache headers, despite what the server
was preconfigured to send.

Actual result:
--
Had to remove the server's configuration section pertaining to caching php
output.

-- 
Edit bug report at http://bugs.php.net/?id=50276&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50276&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50276&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50276&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50276&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50276&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50276&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=50276&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=50276&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=50276&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=50276&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=50276&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=50276&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=50276&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50276&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=50276&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=50276&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=50276&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=50276&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=50276&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=50276&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=50276&r=mysqlcfg



#50276 [Fbk->Opn]: PHP cache headers do NOT override server headers

2009-11-24 Thread vector dot thorn at gmail dot com
 ID:   50276
 User updated by:  vector dot thorn at gmail dot com
 Reported By:  vector dot thorn at gmail dot com
-Status:   Feedback
+Status:   Open
-Bug Type: Apache2 related
+Bug Type: Output Control
 Operating System: Fedora Linux
 PHP Version:  5.3.1
 New Comment:

Yes and no. PHP was not sending the headers that i specified, which
should have overwritten the default server headers. I had to REMOVE the
configuration in the server itself that instructed it NOT to cache pages
ending in "php", before php could send the cache headers to the
browser.

In other words, afaik, php headers are supposed to implicitly have
precedence over default server headers, this can further be ensured by
using the optional second parameter/argument to the header function, and
specifying it to be "true". Both ways php's headers that i wrote
procedurally were never sent to the browser. I had to remove my
configuration in the webserver (httpd.conf) that specified that php
pages are not to be cached. Only then did my php headers that i
specified get output to the client.

The if-modified-since header is not being sent by the browser on
subsequent requests, but that has nothing to do with this bug, and that
is a subject that i am still investigating as a separate issue. I just
mentioned it because i'm retarded, and like to ramble

Thanx ;)


Previous Comments:


[2009-11-24 20:18:59] srina...@php.net


can you kindly rephrase your question. i am not too sure i understand
your question here.

If I understand you correctly, you want to find out a way so that
client (like browser) can request this page with 'If-Modified-Since' in
its header so that the server doesn't have to send it again.

if this is your question, then this is a server configuration issue and
nothing to do with a php engine. 

----------------

[2009-11-24 00:50:29] vector dot thorn at gmail dot com

Description:

If this section is in your httpd.conf:

Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma


Then the cache headers here will not be used:

$expires = 60*60*24*365;
$size = filesize("{$client_directory}/{$_GET['did']}");
$last = filemtime("{$client_directory}/{$_GET['did']}");
header("Content-Length: ".$size,true);
header("Etag: ".md5($last),true);
header("Server: Ionisis.com",false);
header("Cache-Control: max-age={$expires}, public,no-transform",true);
header('Expires: ' . gmdate('D, d M Y H:i:s',($last+$expires)) . '
GMT',true);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last) . '
GMT',true);
header("Content-type: audio/example");
header("Content-Disposition: attachment;
filename=\"{$_GET['did']}\"");
readfile("{$client_directory}/{$_GET['did']}");

and even if you remove that section, and these headers are sent, the
client is still not sending a "if-modified-since" header that can be
captured at the server level for the php level.

Firefox 3.5, Apache 2.2, PHP 5.3, Fedora Linux

Reproduce code:
---
Just copy that code, and paste it in an file called download.php, and
set it up so that it grabs an mp3 file, then beat your head into the
desk for 2 days :D

Expected result:

I expected it to send the proper cache headers, despite what the server
was preconfigured to send.

Actual result:
--
Had to remove the server's configuration section pertaining to caching
php output.





-- 
Edit this bug report at http://bugs.php.net/?id=50276&edit=1



#50276 [Bgs]: PHP cache headers do NOT override server headers

2009-11-25 Thread vector dot thorn at gmail dot com
 ID:   50276
 User updated by:  vector dot thorn at gmail dot com
 Reported By:  vector dot thorn at gmail dot com
 Status:   Bogus
 Bug Type: Apache2 related
 Operating System: Fedora Linux
 PHP Version:  5.3.1
 New Comment:

Thank you for the clarification.
Well in your documentation it states that "the header should replace a
previous similar header", so i thought that it was referring to all
output headers, whereas now i see that it is only other php headers. You
might want to flag that for clarification.


Previous Comments:


[2009-11-25 09:17:32] j...@php.net

Thank you Carsten.



[2009-11-25 07:28:07] carsten_sttgt at gmx dot de

| I expected it to send the proper cache headers,
| despite what the server was preconfigured to send.

No bug in PHP:
Header directives (mod_header) are processed just before the response
is sent to the network (and after any content generator like PHP).
--> and if you configure mod_header to remove e.g. Cache-Control
 from the response headers, it's doing this

Regards,
Carsten



[2009-11-25 07:25:53] j...@php.net

This is propably just Apache issue, I can change any headers using
Fastcgi just fine.



[2009-11-24 21:59:06] vector dot thorn at gmail dot com

Yes and no. PHP was not sending the headers that i specified, which
should have overwritten the default server headers. I had to REMOVE the
configuration in the server itself that instructed it NOT to cache pages
ending in "php", before php could send the cache headers to the
browser.

In other words, afaik, php headers are supposed to implicitly have
precedence over default server headers, this can further be ensured by
using the optional second parameter/argument to the header function, and
specifying it to be "true". Both ways php's headers that i wrote
procedurally were never sent to the browser. I had to remove my
configuration in the webserver (httpd.conf) that specified that php
pages are not to be cached. Only then did my php headers that i
specified get output to the client.

The if-modified-since header is not being sent by the browser on
subsequent requests, but that has nothing to do with this bug, and that
is a subject that i am still investigating as a separate issue. I just
mentioned it because i'm retarded, and like to ramble

Thanx ;)



[2009-11-24 20:18:59] srina...@php.net


can you kindly rephrase your question. i am not too sure i understand
your question here.

If I understand you correctly, you want to find out a way so that
client (like browser) can request this page with 'If-Modified-Since' in
its header so that the server doesn't have to send it again.

if this is your question, then this is a server configuration issue and
nothing to do with a php engine. 



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/50276

-- 
Edit this bug report at http://bugs.php.net/?id=50276&edit=1