Apache 的 mod_cache 不缓存 FCGI PHP 输出

Apache 的 mod_cache 不缓存 FCGI PHP 输出

我有一个非常简单的 PHP 脚本来测试我的 mod_cache 设置。但是,它不起作用——我可以从等待页面加载的 5 秒延迟以及打印的日期看出这一点。

<?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();

此脚本与 mod_php 配合使用效果很好。mod_fastcgi 内容无法缓存吗?我是否需要更改标头才能使内容可缓存?欢迎提出建议。

编辑:添加相关的 apache 配置:

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

GET并显示标题的输出:

[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

答案1

错误 48364Apache 的 bugzilla 最终可能会对此有所帮助,尽管到目前为止还没有。

相关内容