Count active sessions

倖福魔咒の 提交于 2019-12-25 02:46:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!