• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 702
  • Last Modified:

Apache 2.2 mod_disk_chache > How to get it to cache PHP content?

It appears mod_disk_cache is caching things like *.js and *.css files but not dynamic files like PHP or shtml!  For a simple example, the PHP file at the below link prints the time.  If the caching was working, the time would not update - but it does on every page load - give it a try yourself!

The response headers are being set correctly (see below).  And my Apache config is below.  What am I missing?

http://www.t1shopper.com/mod_disk_cache.php

http://www.t1shopper.com/mod_disk_cache.shtml



HTTP/1.1 200 OK
Date: Sun, 10 Apr 2011 22:15:59 GMT
Server: Apache
Vary: Accept-Encoding
Content-Encoding: gzip
Expires: Sat, 03 Mar 2012 13:45:43 GMT
Cache-Control: public
Content-Length: 39
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Content-Type: text/html

Open in new window


LoadModule disk_cache_module modules/mod_disk_cache.so
CacheRoot /var/httpd/proxy/
CacheEnable disk /
CacheDisable /i
CacheMaxFileSize 500000
CacheMinFileSize 760
CacheDirLevels 4
CacheDirLength 2
CacheIgnoreCacheControl Off
CacheIgnoreNoLastMod Off 
CacheIgnoreHeaders Set-Cookie
CacheLastModifiedFactor 30
CacheMaxExpire 2592000
CacheDefaultExpire 2592000

Open in new window

0
Geoff Millikan
Asked:
Geoff Millikan
1 Solution
 
Geoff MillikanAuthor Commented:
Ha, figured it out:

CacheMinFileSize is set to 760 bytes.  There two pages are Content-Length = 39 bytes.  Thus no caching.  Love setting the Apache error_log to debug.

0
 
Geoff MillikanAuthor Commented:
When clicking this URL:
http://www.t1shopper.com/mod_disk_cache.php

I see this really nice entry in the log telling me the cache was used:
[Sun Apr 10 23:04:30 2011] [debug] mod_disk_cache.c(476): disk_cache: Recalled cached URL info header http://www.t1shopper.com:80/mod_disk_cache.php?
[Sun Apr 10 23:04:30 2011] [debug] mod_disk_cache.c(749): disk_cache: Recalled headers for URL http://www.t1shopper.com:80/mod_disk_cache.php?
[Sun Apr 10 23:04:30 2011] [debug] mod_cache.c(282): cache: running CACHE_OUT filter
[Sun Apr 10 23:04:30 2011] [debug] mod_cache.c(296): cache: serving /mod_disk_cache.php

Open in new window

But for this URL:
http://www.t1shopper.com/tools/calculate/file-size/result/?size=654&unit=kilobytes

I see this entry which doesn't really tell me if the cache was used.  So my question is on this entry below, was the cache used?
[Sun Apr 10 23:01:29 2011] [debug] mod_cache.c(131): Adding CACHE_SAVE filter for /tools/calculate/file-size/result/
[Sun Apr 10 23:01:29 2011] [debug] mod_cache.c(138): Adding CACHE_REMOVE_URL filter for /tools/calculate/file-size/result/
[Sun Apr 10 23:01:29 2011] [debug] mod_cache.c(282): cache: running CACHE_OUT filter

Open in new window

0
 
Geoff MillikanAuthor Commented:
Why is it that if we use this URL ( includes the "index.php") then the logs shows the cache was definitely used:
http://www.t1shopper.com/tools/calculate/file-size/result/index.php?size=654&unit=kilobytes


[Sun Apr 10 23:35:15 2011] [debug] mod_disk_cache.c(476): disk_cache: Recalled cached URL info header http://www.t1shopper.com:80/tools/calculate/file-size/result/index.php?size=654&unit=kilobytes
[Sun Apr 10 23:35:15 2011] [debug] mod_disk_cache.c(749): disk_cache: Recalled headers for URL http://www.t1shopper.com:80/tools/calculate/file-size/result/index.php?size=654&unit=kilobytes
[Sun Apr 10 23:35:15 2011] [debug] mod_cache.c(282): cache: running CACHE_OUT filter
[Sun Apr 10 23:35:15 2011] [debug] mod_cache.c(296): cache: serving /tools/calculate/file-size/result/index.php

Open in new window



Do we need to add the "index.php" to everything to make sure the cache is being used?

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Dave BaldwinFixer of ProblemsCommented:
"mod_disk_cache" caches the results of files so if you're caching PHP or shtml pages, it will send the Same page each time.  Usually that's not what you want with PHP or shtml, you're using them to change the page each time.  Which is why is doesn't cache them by default.  Also, it seems that using sessions puts 'no-cache' headers with each page.
0
 
Geoff MillikanAuthor Commented:
I want them cached.  How come it's not caching?
0
 
Dave BaldwinFixer of ProblemsCommented:
Well, because it's not supposed to cache files that are not the same each time.  If it did, the PHP files would only run once and then every user would see the same results page.  Caching is intended to save time on static files, ones that don't change.  There's not much it can do to help a database query page that is supposed to be different everytime.
0
 
Geoff MillikanAuthor Commented:
it's not supposed to cache files that are not the same each time.

It is the same each time, that's why I want to cache it.

Not to be pushy, but do you think you're going to be able to answer the question at hand?
0
 
Geoff MillikanAuthor Commented:
0
 
Dave BaldwinFixer of ProblemsCommented:
Actually you'll end up answering the question one way or another.  All I can do is suggest things to look at, I can't see thru the internet and check your computer myself.  

Are you using any of the things that will cancel caching like sessions?  Have you considered making that page 'index.html' which would define it as a static page?
0
 
Geoff MillikanAuthor Commented:
Anyone else?
0
 
Dave BaldwinFixer of ProblemsCommented:
Click on "Request Attention".
0
 
mattibuttCommented:
Hi
You need to look at the caching on slightly bigger sclae you can use memcache module to cache also look at cms like drupal the pages are built using blocks and you can cache them another alternative is phpsmarty which also jelp caching not every problem answer is caching there are other things you can consider such as the server processors memory and bandwidth.
0
 
Geoff MillikanAuthor Commented:
I appropriate all the feedback however I have a really simple question:

Why isn't mod_disk_cache caching my content like the manual says?
0
 
G-WarrenCommented:
Have you tried using any power tools?
0
 
Geoff MillikanAuthor Commented:
Yep, even tried praying to Matt M at Cornerbone all to no avail, no clues, especially at the Vets Hall.
0
 
Geoff MillikanAuthor Commented:
Ha!  Stumped all the experts!

We made these pages for easier understanding of the issue:

This is cached by mod_disk_cache:
http://www.t1shopper.com/mod_disk_cache_bug/index.php

This isn't cached:
http://www.t1shopper.com/mod_disk_cache_bug/

Anyone know what might cause this?

Thanks,

Geoff
---= Log showing page being written to host's cache =---
mod_cache.c(131): Adding CACHE_SAVE filter for /mod_disk_cache_bug/index.php
mod_cache.c(138): Adding CACHE_REMOVE_URL filter for /mod_disk_cache_bug/index.php
mod_deflate.c(602): Zlib: Compressed 19 to 21 : URL /mod_disk_cache_bug/index.php
mod_headers.c(663): headers: ap_headers_output_filter()
mod_cache.c(639): cache: Caching url: /mod_disk_cache_bug/index.php
mod_cache.c(645): cache: Removing CACHE_REMOVE_URL filter.
mod_disk_cache.c(962): disk_cache: Stored headers for URL http://www.t1shopper.com:80/mod_disk_cache_bug/index.php?
mod_disk_cache.c(1051): disk_cache: Body for URL http://www.t1shopper.com:80/mod_disk_cache_bug/index.php? cached.

Open in new window

---= Log showing page served from host cache to client =---
mod_disk_cache.c(476): disk_cache: Recalled cached URL info header http://www.t1shopper.com:80/mod_disk_cache_bug/index.php?
mod_disk_cache.c(749): disk_cache: Recalled headers for URL http://www.t1shopper.com:80/mod_disk_cache_bug/index.php?
mod_cache.c(282): cache: running CACHE_OUT filter
mod_cache.c(296): cache: serving /mod_disk_cache_bug/index.php

Open in new window

---= Log showing "forward slash page" not served to client =--- 
mod_cache.c(131): Adding CACHE_SAVE filter for /mod_disk_cache_bug/ 
mod_cache.c(138): Adding CACHE_REMOVE_URL filter for /mod_disk_cache_bug/ 
mod_deflate.c(602): Zlib: Compressed 19 to 21 : URL /mod_disk_cache_bug/index.php

Open in new window

We're on:
httpd-2.2.3-45.el5.centos.x86_64.rpm

0
 
Dave BaldwinFixer of ProblemsCommented:
Because it's not a File?  Maybe redirection to the 'default' page occurs after checking the cache?  Finding the default page may also occur after checking the cache.  It can be one of a number of different file names in addition to 'index.php' like 'index.html', 'index.htm', 'index.shtml' that are listed in the directory setup for that site.
0
 
Geoff MillikanAuthor Commented:
I've classed this as bug now in Apache:

https://issues.apache.org/bugzilla/show_bug.cgi?id=51057

0
 
Geoff MillikanAuthor Commented:
Bug is fixed in Apache version 2.2.17 but this isn't back ported in RHEL5, CentOS5, OL5, etc. If you need mod_cache to work as expected, you have to compile from source or use a vendor version of Linux that uses the very latest version of Apache.

https://issues.apache.org/bugzilla/show_bug.cgi?id=45273 
0
 
Geoff MillikanAuthor Commented:
Bug in "vendor's" code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now