Megan Caithlyn
Megan Caithlyn

Reputation: 383

How to find out when the script was executed last time in PHP?

I want to create a PHP script, which would be launched regularily as a cron job. But sometimes I may launch it manually. The script must modify MySQL rows created from the time of its last execution and I want to avoid modifying the same row twice. Each row contains its creation time. I don't want to clutter my database with a whole column to hold last modification time for each row.

To narrow the problem down, I need a variable $last_execution_time to hold a timestamp, written on the last script execution.

What is the correct and elegant way to do this?

Upvotes: 0

Views: 297

Answers (2)

splash58
splash58

Reputation: 26153

You can write time to file.

When script is running, lock the file, to avoid the simultaneous calls problem

Upvotes: 1

accepto
accepto

Reputation: 1

Pull out the last known record from the DB.

Select lastupdatetime from table limit 1 order by id desc

Make a check to see if it's before current time stamp etc

So use the data in the database to help yo

Upvotes: 0

Related Questions