What you may do is to store into a database the clients who have hit your web site in the past few minutes (usually, five minutes).
If you have authenticated users, you can use cookies (or any other authentication method you use) to identify the user every time it comes to your web site.
If you need to count users who are "guests" you can do that by counting the different IP addresses that had hit your site in the past few minutes: it's not perfect, but it'll give you a more or less approximately correct number. The IP address of the client is in $ENV{'REMOTE_ADDR'}.
Michele.