A
A
Alexander2016-08-20 12:58:05
Yii
Alexander, 2016-08-20 12:58:05

How to correctly count online on the site?

It is necessary to implement a count of active users on the site at the moment. It is not necessary to count those who opened the site and forgot about it for half a day. At what it would be desirable to make updating in real time. That is, if, for example, a person closes the tab, then it will immediately be displayed to others. I will update the value through web sockets, so the main thing is to count online on the server on time, competently and with good performance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Максим Тимофеев, 2016-08-20
@webinar Куратор тега Yii

в afterAction контроллеров юзеру присваивать переменную lastActive в которую писать unix метку времени, например в базу ее писать. Потом делать выборку пользователей у которых lastActive больше, чем сейчас минус 15 минут например.
Можно вынести это в поведение или в компонент и подключить в конфиге.

Артур, 2016-08-26
@ArturF

> I will update the value through web sockets
and what will act as a queue server? If it is a node, then store it in a variable thread. And you can increment/decrement on connect/disconnect events and then send the updated value to subscribers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question