I'm trying to show my website's users a time/date (which determines the last time of their visit of my website) in their profile page. Something exactly like this:
Well how can I calculate that number (8 min ago) ?
Currently I have a table like this:
// requests
+----+----------+-------------+
| id | id_user | unix_time |
+----+----------+-------------+
| 1 | 2353 | 1339412843 |
| 2 | 2353 | 1339412864 |
| 3 | 5462 | 1339412894 |
| 4 | 3422 | 1339412899 |
| 5 | 3422 | 1339412906 |
| 6 | 2353 | 1339412906 |
| 7 | 7785 | 1339412951 |
| 8 | 2353 | 1339413640 |
| 9 | 5462 | 1339413621 |
| 10 | 5462 | 1339414490 |
| 11 | 2353 | 1339414923 |
| 12 | 2353 | 1339419901 |
| 13 | 8007 | 1339424860 |
| 14 | 7785 | 1339424822 |
| 15 | 2353 | 1339424902 |
+----+----------+-------------+
As you see table above stores all my website's requests. I mean I insert a new row into that table when user opens (loads) any page of my website. And then to calculate last_seen, I simply select last row for that specific user and use him unix_time
value.
To be honest, I guess what I'm doing is wrong (or at least isn't standard). Because there is a lot of costs to calculate just a last_seen.
Also some days ago, I saw a file named access_log.txt
in the server which was containing all requests. Now I want to know can I use that file for doing that? Also would it be better than my current approach (using database) ? In total, how can I calculate last_seen for each user?