How to determine the number of active connections on my site? When entering the site, give to the one who connected, some id and write to the database, and delete when you exit?
- And how do you want to determine the fact of exit? - ilyaplot
- For what purpose do you need it? - Bookin
- Yes, and under active connections, what is meant is also not clear. - Evgenii Izhboldin
- @Bookin to select two random users and allow them to send text messages to each other. Chat. - Sergey Alekseev
- As I understand it on php, without special tricks, you can only determine the time of the last activity, the user - Evgenii Izhboldin
|
1 answer
Option 1. Track the latest activity.
The answer was taken from the English version by @Sampson
Whenever a user accesses a page, update the last action field in the
Userstable. Then make a request (or hang up the task incron) for all users who have been active for the last 5 minutes. The rest translate intoofflinestatus.If you need to know that they are active, although they do not go to other pages, then you can add something like a
javascriptpingsetInterval(function () { $.get("stillAlive.php"); }, 60000); //60000 - 1 минута, можно свое время задатьOption 2. If you need to accurately track online users, use Websockets.
For php there is for example an article . It has instructions and how to make your bike, and links to frameworks.
|