PHP: An impossible task? Determine last accessed date/time by httpd

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Reaction score
13
An idea popped into my head and since some of you have a deeper understanding of all things OS/PHP (Linux too... since I'm only really starting to get into LAMP now), I was wondering:

Is it possible to determine the last accessed date/time of a specific php (or html) file by the Apache/NGINX server?

And by possible I mean *easy* and NOT resource intensive (since I realize you could scan the access logs for this data)

The reason why I ask is because, since my caching question, I've been thinking of writing out an html file (generated from the 3rd party API I'm using) and mod_rewrite the URL to check if a file for it exists or to do a new API call/file generation for the item being searched for or viewed.

Then based on access date/time, be able to remove older files or even just use it as an indicative tool as to what is trending on my site.

NO I DON'T WANT TO USE A DATABASE! ;) A database would defeat the point of this exercise for me :D
 
Your http server will record every file hit with a unix time stamp. I suppose you could write a script to check that?
 
Yeah, your http server will record every file hit with a unix time stamp.

I was just about to add "with the atime disabled on the server for increased performance to file access" :D

But I think it shouldn't be a problem performance wise... or has someone come across the atime-performance enhancement giving a significant boost overall?
 
use memcached can store pairs in memory and point to a localized resource.
 
Not sure what you're trying to do but...

You have the creation date of the HTML cache file, so you can use that to check how old it is from the current request (1 day old, 1 week old etc.) and if it needs to be removed and recreated.

But all of this is just re-inventing the wheel why not use Zend_Cache or Cache Lite, use the file cache and set the lifetime to be 1 day, 1 week or whatever you need?

If you just want the last accessed time, as semaphore says, you can log the access time and file name to APC or memchache using the filename as the key:
mytest.php -> 2010-10-08 10:00
Or, if you're using APC, you can find the last accessed date of a file by viewing the entry in the APC control panel.
 
Last edited:
Thanks. I want to try and avoid Zend as much possible since I'm running on 5.3.3 and Zend are a bunch of slow-douches
 
Not sure what you're trying to do but...

You have the creation date of the HTML cache file, so you can use that to check how old it is from the current request (1 day old, 1 week old etc.) and if it needs to be removed and recreated.

But all of this is just re-inventing the wheel why not use Zend_Cache or Cache Lite, use the file cache and set the lifetime to be 1 day, 1 week or whatever you need?

If you just want the last accessed time, as semaphore says, you can log the access time and file name to APC or memchache using the filename as the key:
mytest.php -> 2010-10-08 10:00
Or, if you're using APC, you can find the last accessed date of a file by viewing the entry in the APC control panel.

I already have APC installed (I think). How do I access the control panel?
 
You can always try Synfony reloaded then?

Stay the hell away from Symfony. I've been using it for 3yrs (version 1.0, actually before it even went 1.0) and since 1.2 I hate it. Documentation is a mess and you spend hours in 1.4 what takes me 10 minutes in 1.0
 
Thanks. I want to try and avoid Zend as much possible since I'm running on 5.3.3 and Zend are a bunch of slow-douches

find -name apc.php. /usr/share/php/apc.php on Debian based machines.

Move it to somethwere accessible by your webserver. Look under "system cache entries".
 
Top
Sign up to the MyBroadband newsletter
X