Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
Can you add your Apache configuration and the output of "GET -Sed your.server/your.script.php? –  markdrayton Oct 13 '09 at 16:35
    
"GET -Sed your.server/your.script.php";, I mean. –  markdrayton Oct 13 '09 at 16:35
    
Okay, so http:// is trimmed out :~) –  markdrayton Oct 13 '09 at 16:36
    
@markdrayton: Added. let me know if you need more of httpd.conf –  Josh Oct 13 '09 at 21:42

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
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 '10 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.