What could be adding "Pragma:no-cache" to my response Headers? (Apache, PHP)

24,609

Solution 1

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!

Solution 2

The culprit may be php.ini, where session.cache_limiter=nocache. Change the value to blank or public to avoid the anti-cacheing headers.

Solution 3

I had a similar problem with Pragma: nocache

session_cache_limiter(false); prior to session_start(); seemed to suppress it.

Solution 4

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.

Solution 5

I did this at runtime with this:

header("Pragma:");

which forced the script to unset the Pragma header.

Share:
24,609
recursive9
Author by

recursive9

Founder of Crystal Gears Portfolio: - www.movertrends.com - www.friendshopper.com - www.digitalshow.com - www.translatorscorner.com - www.gigpay.com

Updated on February 11, 2021

Comments

  • recursive9
    recursive9 over 3 years

    I have a website which 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 what could be setting those "pragma" (and "cache-control") headers, and how can I avoid it?