计算并限制我的应用程序上的用户数量 [英] Count and limit the number of users on my app

查看:146
本文介绍了计算并限制我的应用程序上的用户数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实施一个系统来限制可以同时使用我的应用的用户数量.我认为最好的方法是计算当前活动的会话数,然后根据该数量进行限制.

如何计算当前活动的会话数.我正在使用memcached存储会话,如果有帮助的话

我认为最简单的方法是拦截会话的opendestroygc回调(使用 解决方案

I think the easiest way is to intercept the session's open, destroy and gc callbacks (using session_set_save_handler()) and increment/decrement a session count value within memcached. Something like:

class Memcache_Save_Handler {

   private $memcached;

   public function open($save_path, $name) {
      $session_count = (int)$this->memcached->get('session_count');
      $this->memcached->set('session_count', ++$session_count);
      // rest of handling...
   }

   public function destroy($id) {
      $session_count = (int)$this->memcached->get('session_count');
      $this->memcached->set('session_count', --$session_count);      
      // rest of handling...
   }

}

这篇关于计算并限制我的应用程序上的用户数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆