Try this command to print out the number of established connections to
port 80 (i.e., your webserver)

netstat -an | grep "ESTABLISHED" | grep ".80 " | awk '{print $5}' |
sed 's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)\.[0-9]*/\1/' | uniq | wc -l

Since browsers tend to open multiple connections at once, I've
filtered out repeated lines so that they will only count as a single
connection.  The number might not be accurate if many of your users
are sitting behind NAT.

I've only tested this FreeBSD, but it should work with other Unix and
Linux distros as well...

[ simon.cpu ]

On Tue, Jan 19, 2010 at 12:23 AM, Michal Charemza
<[email protected]> wrote:
> I imagine there are a few different ways. A naive way would be:
> - Have a database table "OnlineUsers": with "id" and "time" fields
> - In your User class, in the initialize method either
>   - Insert a new row to the table, and store the ID in the session (as a
> User attribute)
>   - If there is already an ID in the session, update the row with the ID
> with the current time
> Then, in a slot, you could query the database to find out how many people
> have looked at a page in the last X minutes, to get the number of online
> users.
> *However*, this would mean 2 database requests per page load. So you could
> - Use caching on the slot, with a lifetime of X minutes
> - Also store "time" in session, and then only update the time in the
> database if the last page load time by that user was more than X minutes
> ago.
> Michal.
>
> On 16 Jan 2010, at 20:49, Mahmood reza Delfieh wrote:
>
> Hello
>
> Gow can I count numbers of online users?
>
> Best Regards
> Mahmood
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.agavi.org/mailman/listinfo/users
>
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.agavi.org/mailman/listinfo/users
>
>

_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to