I'm looking for an easy (no database) method of listing how many users are active on a website. The easiest way I can come up with is by counting the number of open sessions.
This code should work:
$number_of_users = count(scandir(ini_get("session.save_path")));
Of course it won't because of the security constraints on that directory (as there should be!!). Does anyone know another way to access this number without changing directory permissions.
Note: I'm looking for an option that does not involve databases or reducing the security on PHP sessions.
End Note: For anyone coming to this question, I ended up using a cronjob (running every minute) from root that did something similar to:
ls /var/lib/php5/ | wc -l > /var/www/sessioncount
Make sure the /var/www/sessioncount
file is readable by the apache user. Then you can just read the file in PHP:
$number_of_users = file_get_contents("/var/www/sessioncount");