Re: Counting Online users, but not using a Session Table in MySQL
| From: | Jim Lucas | Date: | Fri, 28 Jan 2011 18:15:24 +0000 |
| Subject: | Re: Counting Online users, but not using a Session Table in MySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311070@lists.php.net to get a copy of this message | ||
On 1/28/2011 9:57 AM, AmirBehzad Eslami wrote:
> Dear list,
>
> The common solution for counting online users is to store sessions in a Table.
> I've created a Table in MySQL to acheive the result, but it seems this solution
> is a little heavy for such a simple task.
>
> Is there a better alternative? Can I use SqlLite to make COUNT(*) queries based
> on a where statement?
>
> Is there any better solution? Do you know any way to store sessions in Memory?
>
> Does Memcache support counting sessions?
>
> I'm looking for a high-performance solution to count online users.
> What do you think?
>
The simple way that we do it is to have users table have a boolean field that
gets updated when a person logs in, then a time field showing when they last
visited. These together should give you the information that you are looking for.
This gives you the idea...
SELECT COUNT(*)
FROM users_table
WHERE logged_in = 't'
AND last_activity > FROM_UNIXTIME( UNIX_TIMESTAMP() - 1800 )
Jim Lucas