Questions about judging whether the user is online!!!
Has been heard how to determine whether the user online this topic, has not been the essentials, today specifically to ask you!! Thank you, everyone!!
Share to:
------Solution--------------------
Log the session to the database, and also identify the user ID number, determine whether the user online to see if the ID number corresponding to the session information is expired. Do not know what I said is not right, welcome downstairs the big God shoot bricks.
------Solution--------------------
The main is to determine the last activity time, set a shorter default online time, if there is no activity record in this time is not considered the line;
------Solution--------------------
1, why should I judge whether the user is online?
Since the user is not on the line, he will not make a request to you.
Unless you have a need to show the number of people online
2, when to determine whether the user is online?
When you need to show the number of people online, it's natural that at least one user has made a request
Count the number of people online only when the request is ringing
What's the use of statistics if no one else has access to your site?
3, how to judge the user online?
Whether or not to register a user, only the number of valid sessions can be counted.
If you feel that the default session expiration period of 1440 seconds is too long, you can adjust as you want
------Solution--------------------
Log user last access time
Check the interval between the user's last access time and the current time, if beyond the agreed range, is considered not online
Determine if User A is online work is performed during User B activity
Judgment is performed independently on the server side, regardless of the client
------Solution--------------------
You can use a memory table to update the user's last operation time, and then use Cron to perform cleanup of the user's actions on a regular basis, so that the list is the most recently online user.