How to handle user online status when he/she close the browser?

后端 未结 5 970
自闭症患者
自闭症患者 2021-01-06 01:47

I am having table to track user online status by setting \'is_online\' field to 1. Now User get logged in the site and shut down his/her system or power down at that time he

5条回答
  •  别那么骄傲
    2021-01-06 02:12

    The normal solution is to store a timestamp in the table which you update every time the user does something. Users with a recent timestamp (say, five minutes) are shown as logged in, everybody else are logged out.

    It doesn't even have to be updated on every page load. Keep a timestamp in the session with the last update time as well, and only update the table when the database flag are about to expire.

提交回复
热议问题