I'm trying to code (in an efficient way) a log to count how many hours a user spent on the system.
The only reliable information is the login date and time. User's often just close the window and don't log off.
What I've been doing so far is to use a jQuery call every 5 or 10 seconds to a specific endpoint to just record: user's id and the current datetime. But this is, of course, very expensive. A lot of HTTP requests (imagine for 8 hours a day how many requests) and a huge (HUGE) table.
Is there a more efficient way to count this information and present a summary of worked hours by the end of the month?
I'm currently using MySQL to log this (another table inside the same database) but I can use a different database if it's a better solution.