T
T
tigra2015-12-23 11:48:42
Yii
tigra, 2015-12-23 11:48:42

How to display all users online?

I am making a portal, I need to display all users who are currently on the site.
Maybe there are some built-in solutions of the framework?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Beloborodov, 2015-12-23
@tigroid3

There is not.
This is done simply.
When you go to the page, you update the time of the last update in the users table. Something like this:

$sql='UPDATE users SET last_update='.time().' where id_user='.Yii::app()->user->id;
Yii::app()->db->createCommand($sql)->execute();

And sampling everything online
$users=Users::model()->findAll([
    'condition'=>'t.last_update > :time',
    'params'=>[':time'=>time()-(60*60*15)], // 15 минут
]);

A
Alexander, 2015-12-23
@Sassoft

Or you can write in memcash

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question