Thinking about it well, you could implement it differently.
How to implement it quietly, simply
session_start(); $_SESSION['timestamp'] = time();
This will be indicated above in the script.
When the script stops, it will be saved in your database, but stop, we will not finish: P
Then you check if the timestamp in the current record is higher or lower. if it is lower, it is updated, otherwise forget to update and just do nothing. Microtime () should be considered. because people like to press f5.
So, a new idea, and I think it works a little better and saves on production
To reply to a comment:
Look at the session handler , you can make your own function how php processes the session. Thus, you do not need to reorganize the code, add it.
Then, in the part of the record, you will tell the database to update the record with the identifier x and where the timestamp is above the specified value.
To implement, you must add a column to the / mincrotime timestamp. And in the session handler, you save the request time. Therefore, you can make a comparison. Then you do not need to save time in the session either :) (not in $ _SESSION, it is saved in db!)