views:

275

answers:

4

I have a website whose maintenance I've inherited, which is a big hairy mess.
One of the things i'm doing is improving performance. Among other things, I'm adding Expires headers to images.

Now, there are some images that are served through a PHP file, and I notice that they do have the Expires header, but they also get loaded every time.

Looking at Response Headers, I see this:

Expires Wed, 15 Jun 2011 18:11:55 GMT
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma  no-cache

Which obviously explains the problem.

Now, i've looked all over the code base, and it doesn't say "pragma" anywhere. .htaccess doesn't seem to have anything related either.

Any ideas who could be setting those "pragma" (and "cache-control") headers, and how I can avoid it?

Thanks!
Daniel

+1  A: 

If it's not in .htaccess it may be in the main Apache config file - or one of its includes, depending on the setup.

Colonel Sponsz
Any ideas how to override it from my .htaccess? (I don't have SSH access to this server, or access to httpd.conf)
Daniel Magliola
Not sure how to *remove* a header actually - try asking on serverfault.
Colonel Sponsz
A: 

Run grep -R pragma . to look through the files.

mcandre
Did that. Nothing. That's what I meant by "I looked all over the code base"
Daniel Magliola
+1  A: 

Create a simple file that includes none of your PHP libraries but lives in the same folder as the file that serves up your images through a PHP file.

file: test.php

Request this file through a browser and check the headers. If you see the Response headers that you don't want, you know that they're configured via apache and not generated via a PHP file and you can concentrate your searches on .htaccess file in the directory tree, and on the http.confg and other included apache config files. You'll want to search for

<Directory....

and

<VirtualHost

sections that may apply to your site.

If you don't see the headers in a request for that simple PHP file, you know that PHP is setting the headers somewhere. At the end of your image serving file (or right after it echos the image and exits), but the following PHP snippet)

var_dump(get_included_files());

Request an image through the image serving URL. That above snippet will print out all the PHP files used in the request. (you'll probably need to view source or use curl to see the raw output, as the browser will report an invalid image)

Having a subset of your files to work file, search through them for calls to the

header();

function. The header function is the only way (I think) that raw PHP code can set Response headers. You'll also want to search for

call_user_func
eval
$$

in case there's any dynamic code on the page that's using PHP's meta-programming capabilities to call the header function.

Good luck!

Alan Storm
Wow, thank you for the detailed answer. It's definitely Apache's configuration, but I don't have access to it. I only have FTP access to my website's directory. Any idea how I can override/remove these headers using only my .htaccess files?
Daniel Magliola
Unfortunately, that's too general to quickly come up with an answer. You'd need to know which Apache directives were causing the caching in over to override the effects AND need to know if they were overridable in .htacess AND know the syntax to do so. Rather than waste too much time I'd raise this up the chain to the server admins and see if they can't help you, as "caching by default" isn't the default configuration of Apache and/or the PHP module. #nothelpfulsorry
Alan Storm
Thank you very much.
Daniel Magliola
+1  A: 

Try unsetting the headers in .htaccess. The below example will unset them for all files matching the extensions ico, jpeg, png, gif, js, css:

<FilesMatch "\.(ico|jpeg|png|gif|js|css)$">
    Header unset Cache-Control
    Header unset Pragma
</FilesMatch>

You can find some hints in this article.

BalusC