Well thinking about it you could implement in a other way.
How to implement it is quiet simple
session_start();
$_SESSION['timestamp'] = time();
This will be put above in your script.
When the script stops it will be saved to your database, but wait stop, we are not done :P
Then you check if the timestamp in the current record is heigher or lower. if it is lower then update, else forget to update and just do nothing. Should consider microtime(). because people love to press f5.
So new idea, and I think it works a little bit better and saver for production to
To answer the comment:
Look at session handler, you can make your own function how php handles session. So you don't have to refactor you code, only add.
Then in the write part, you say to the database update the record with id x and where the timestamp is higher then the given value.
For the implementation you should add a column to the record timestamp/mincrotime. And in the session handler you save the time it was request. So you can make the comparison. Then you don't need to save the time in the session either :) (not in the $_SESSION, it is saved in the db!)