Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Can't get Apache mod cache working

creating caches but not reading from them

     

wulawula

11:06 am on Nov 29, 2007 (gmt 0)

10+ Year Member



I'm trying to set up apache mod_cache to cache dynamic pages (generated by PHP) so as to accelerate this server. Now Apache can create lots of cache files in the specified folder. The problem is that apache doesn't read from these caches to feed requests.

1. My server environment is REDHAT Enterprise 3 i686 on standard - WHM X v3.1.0 + Apache 2.2.6 + PHP 5.2.5 .
2. I've installed modules including mod_cache, mod_disk_cache, mod_mem_cache and mod_expires.
mod_cache related settingsú║
CacheRoot /home/apachecache
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
CacheDefaultExpire 86400
CacheMaxExpire 86400

3. I add the following lines in the test php page to make apache cache the result:
<?php
header("Expires: " . gmdate('D, d M Y H:i:s', time()+3600*72) ." MT" );
header("Last-Modified: ".gmdate('D, d M Y H:i:s') . ' GMT');
header("Cache-Control: public,max-age=604800");
?>

4. I also add the following lines to the test page so that I can tell whether it is read from cache:
<?php
echo date("H:i:s");
?>

After the above settings, I can see cache files are created but the page itself is always 'fresh' . Anybody here can help me? Thanks!

gergoe

6:16 pm on Dec 5, 2007 (gmt 0)

10+ Year Member



Caching behavior is also affected by the client (browser), so first I'd make sure it is not the case, by either changing the caching parameters of the browser, or by checking the Apache with a software which shows the http headers (of the request and the response too). Second, the php has some influence on this, if the sessions are enabled (started) it sets numerous cache restricting headers.

wulawula

12:36 am on Dec 6, 2007 (gmt 0)

10+ Year Member



Thanks gergoe! I found it was highly related with the browser's header. It is not a big problem since the reason is found and now everything is ok now.