问题
I store my sessions with memcached. I am looking to detect how many active sessions there are currently.
I am convinced it must be possible - But I have googled and googled but to no avail so please stackoverflowers give me some guidence :)
回答1:
Memcached by nature isn't meant to be used like that (it's a fleeting cache store, it is not intended to do SQL / database like aggregate queries over), and current active sessions is usually not something I am remotely interested in (for load purposes, the hits & statistical data of the webserver is much more to the point).
If you are however use memcache only to store session-data (not other key-value pairs), you can use getStats() to get an item count (cur_items) on the current memcache server.
回答2:
You can use set_session_save_handler to save your sessions to a database, then getting active sessions is as easy as querying the database.
来源:https://stackoverflow.com/questions/4071764/count-active-sessions