我有一个非常简单的PHP脚本来testing我的mod_cache设置。 然而,它不工作 – 我可以通过等待页面加载5秒延迟和打印date。
<?php ob_start(); header('Last-Modified: '.gmdate('D, d MYH:i:s', filemtime(__FILE__)).' GMT', true, 200); header('Cache-Control: max-age=31536000, public',true); header('Pragma: Public',true); header('Expires: ' . gmdate('D, d MYH:i:s', strtotime('now + 10 years')) . ' GMT',true); header("Vary: Accept-Encoding"); header("Content-Type: {$mime}",true); sleep(5); echo "test: ".date('n/d/yg:i:s A'); header('Content-Length: '.ob_get_length()); ob_end_flush();
这个相同的脚本在mod_php下工作得很好。 可以mod_fastcgi内容不被caching? 我是否需要更改标题才能使内容可caching? build议欢迎。
编辑:添加相关的Apacheconfiguration:
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
关于Apache的bugzilla的Bug 48364可能最终有助于解决这个问题,尽pipe目前情况并非如此。