I have a PHP variable $ _SESSION with username. I have a MYSQL database with a unique field for the username. How can I keep db up to date with the names of online users and also delete them when they leave. Is there a way to do this using jQuery.ajax?
As I do this, a special handler pings using AJAX periodically (once every 30 seconds). This is a lot of requests, so instead of updating the online user table every time with the last visit, I update memcache. I only update the database record when it is 5 minutes behind the memcache record (you can choose a longer or shorter delay depending on the load). The cron job then deletes obsolete entries from the online user table.
To check if a particular user is online, I just check his memcache entry. Error no more than 30 seconds. The database does not exceed 5 minutes, so the results from the database are also quite accurate.
I also use these periodic queries to input events to the user.
, . , , 5 , cron, - , 5 .
, -. , 2 .
, , - . , - last_login last_seen , .
last_login
last_seen
, , . , last_seen , , . (15 , 30 ?) , .
ajax , , , - last_logout, :
last_logout
- MySQL MEMORY, / ( ). , timestamp ( /). , userID , ( ) cron, , , 5 . , cron. ? ( ), , .
Source: https://habr.com/ru/post/1793291/More articles:How to change PATH for RubyMine system-wide? - pathEmail Handler KRL - krlIs the cloud another name for web hosting? - cloudThe index was out of reach. Must be non-negative and smaller than the size of the collection - c #Как разобрать загруженный txt файл в Rails3 - htmlMark editor for objective-c - objective-cCross-platform autorun - c ++Как получить уникальные случайные элементы из массива? - arraysUsing the alarm manager to start a service - androidRails runner script не работает - rubyAll Articles