PHP Count Logged-In Users

后端 未结 3 811
醉酒成梦
醉酒成梦 2020-12-09 00:24

I\'m having trouble figuring out how I can count the number of logged-in users in my application.

What I have: When a user logs in, they get a sessi

3条回答
  •  轮回少年
    2020-12-09 00:57

    Just to offer another solution:

    if ($user->isLoggedIn()) {
      touch("/writable/path/loggedInUsers/" . $user->id);
    }
    

    If you don't need to query this data, a local file touch is far faster than a DB write. To get logged in users, scan the directory for filemtimes under N seconds old.

提交回复
热议问题