tags:

views:

34

answers:

3

I am looking to make a script that runs and uses the time stamp of the last time it ran as a parameter to retrieve results that have been updated since that time. We were thinking of creating a database table and having it update that and then retrieve the date from there, but I was looking for any other approach that someone might suggest.

A: 

This might work: http://us.php.net/manual/en/function.fileatime.php (pass it $_SERVER['SCRIPT_FILENAME'])

Hans
The problem with this would be if you edit the script or anything else accesses it, you will get an incorrect time.
Alan Geleynse
Good point Alan; seems that many systems are disabling atime updates, too, for performance, so atime may not even be updated on all systems
Hans
A: 

Your best result would be to store your last run time. You could do this in a database if you need historical information, or you can just have a file that stores it.

Depending on how you run the script, you may be able to see it in your logs, but storing it yourself will be easier.

Alan Geleynse
+1  A: 

Using a database table to store the last run time is probably the easiest approach, especially if you already have that infrastructure in place. A nice thing about this method is that you can write the run time right before the script terminates, in case it runs for a long time and you do not want it to start up again too soon.

Alternatively you could either write a timestamp to file (which has it's own set of issues) or attempt to fish it out of a log file (for example, the web access log if the script is being run that way) but both of those seem harder.

Justin Ethier
Thanks Justin, good to know we were on the right track. I just wanted to make sure there wasn't something better out there.
dan.codes