Forum Moderators: phranque

Message Too Old, No Replies

how to make apache log cached images/videos as hits?

has to do something about mod_expires?

         

majestique

3:00 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Hi everyone, does anyone know how to make apache log cached videos? My site delivers video ads so I want to be able to log cached videos when a user views my ad more than once.. someone said it has to do something with mod_expires - but will that make the user re-download the file.. or maybe the best bet is to write a script to log it? Thanks!

jdMorgan

3:42 am on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



majestique,

It's not a matter of making Apache log cached content requests, it's a matter of getting the client browser to access your server even when re-loading previously-cached content, which it won't usually do. If the browser accesses your server, then your server can log the access. If not, it can't.

You can use Apache mod_headers [httpd.apache.org] to send a cache-control header to the client browser with each of your multimedia files. If you specify "no-cache, must-revalidate", then browser reloads of these cached files will result in a 304-Not Modified entry in your log file.

Be aware that "no-cache" doesn't mean "Don't cache this file" - It means "This object may be held in any cache but it must be revalidated every time it is requested." And "must-revalidate" is needed to tell most caches to take you seriously when you tell them "no-cache".

The following Apache code sets the cache-control header for any file which has a name starting with "ads" and ending with ".avi". This is specified using the regular-expressions [etext.lib.virginia.edu] pattern in the <FilesMatch> container. This code may be used in .htaccess or in httpd.conf.

I use Header unset and Header append, rather that Header set, because I once ran into a quirky system where Header set didn't work. You can try using Header set if you like.


<FilesMatch "^ads.*\.avi$">
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>

Jim

majestique

5:20 am on Apr 27, 2004 (gmt 0)

10+ Year Member



Thanks Jim! This is not a sure-fire way is it? It may be 90% effective right? If there's no foolproof method from apache.. then it seems like I have to write a script myself that logs every view... Thank you for your answer! Much appreciated =) www.liketelevision.com has a script.. but don't know how much they're selling it for :-/

jdMorgan

1:30 pm on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> This is not a sure-fire way is it?

>> browser reloads of these cached files will result in a 304-Not Modified entry in your log file.

That's all I can tell you. It works for me. There's a very slight possibility that some broken proxy caches on the network or some very old or primitive browsers might not do what you want. There's also the possibility that I misunderstood your needs, and that what you want to do is impossible, but I suggest that you try it.

The biggest problem I expect you will have is that if you have not been sending any cache-control or expires headers in the past, then you'll have to wait for those old cached files to expire in the users' caches before they will come fetch a new copy that includes your new headers. Normally, this will happen after a few days anyway. If you need 'instant results', then rename the files or put them into a new subdirectory and change your links to them. This will make their browser think they're something new, and force it to go to your server.

Jim

majestique

9:27 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



Does your code work in apache 2.0? if so where do i put it in the httpd.conf file? i tried adding that code to the .htaccess file and it restricted access to everything @_@

majestique

9:32 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



by the way.. i have ie 6.0 and whenever i view the cached video.. apache logs it.. i suppose i should test out netscape/older ie browsers/etc to make sure they all log cached hits..

jdMorgan

11:36 pm on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code should work in any modern version of Apache, as long as the mod_headers module is loaded at startup.

If you are getting an error, check your error log and see what it tells you.

Jim