0

I have a very simple PHP script to test my mod_cache setup. However, it's not working -- I can tell by both the 5 second delay when waiting for the page to load as well as the date printed.

<?php

        ob_start();

        header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime(__FILE__)).' GMT', true, 200);                               
        header('Cache-Control: max-age=31536000, public',true);
        header('Pragma: Public',true);
        header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('now + 10 years')) . ' GMT',true);
        header("Vary: Accept-Encoding");
        header("Content-Type: {$mime}",true);

        sleep(5);

        echo "test: ".date('n/d/y g:i:s A'); 

        header('Content-Length: '.ob_get_length());
        ob_end_flush();

This same script works just fine with mod_php. Can mod_fastcgi content not be cached? Do I need to change the headers in order to get the content to be cacheable? Suggestions welcome.

EDIT: Adding relevant apache config:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiConfig -idle-timeout 20 -maxClassProcesses 1

AddHandler php5-fcgi .php
Action php5-fcgi /cgi-bin/php.fcgi

<Location "/cgi-bin/php.fcgi">
   Options ExecCGI
   SetHandler fastcgi-script
</Location>

ExpiresActive On
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"

<FilesMatch "\.(jpg|png|gif|jpeg|bmp|ico)$">
   Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

CacheEnable disk /
CacheRoot /var/www/cache
CacheDirLevels 3
CacheDirLength 1
CacheDefaultExpire 10
CacheIgnoreCacheControl On

And output of GET showing headers:

[jnet@workingman public_html]$ time GET -Sed http://localhost/cachetest.php
GET http://localhost/cachetest.php --> 200 OK
Cache-Control: max-age=31536000, public
Connection: close
Date: Tue, 13 Oct 2009 21:40:17 GMT
Pragma: Public
Server: Apache/2.2.3 (Red Hat)
Vary: Accept-Encoding
Content-Length: 25
Content-Type: 
Expires: Sun, 13 Oct 2019 21:40:17 GMT
Last-Modified: Tue, 13 Oct 2009 12:40:57 GMT
Client-Date: Tue, 13 Oct 2009 21:40:22 GMT
Client-Peer: 72.52.238.75:80
Client-Response-Num: 1
X-Powered-By: PHP/5.2.11


real    0m6.261s
user    0m0.198s
sys     0m0.823s
4

1 Answer 1

1

Bug 48364 on Apache's bugzilla may eventually help with this, although as of now it doesn't.

1
  • Looks like exactly my issue, thanks! In the meantime I solved it by having my server be a caching proxy to itself for PHP scripts. A bit slower perhaps but the caching works then.
    – Josh
    Feb 21, 2010 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .