Hi,
I'm looking for an efficient way to count the 'online' logged in users in a Laravel 9 application. Since the application can have a lot of peak traffic (between 500 and 1000 concurrent users), I'd prefer not to use a database driven solution.
Redis and websockets are an alternative option. However, I would like to save on connections and messages for the websocket plan.
I see a lot of discussions on this topic online. However, I don't understand why people don't simply count the number of sessions. Is it correct to assume that the session count will give you the number of active users during the last hour if the session duration is set to 1 hour? Of course this info does not reflect an 'on-the-fly' information, but it avoids doing some extra action at every request.
OpenAI chat gave me following answer on 'how to count the number of sessions...' . However it keeps returning zero users online, even when users are logged in.
use Illuminate\Session\SessionManager;
$sessionManager = app(SessionManager::class);
$sessionStore = $sessionManager->driver('file');
$sessionIds = $sessionStore->all();
$numberOfSessions = count($sessionIds);
echo "There are {$numberOfSessions} active sessions.";