/** * @param $app \Linger\Core\App */ public function initSession($app) { $session = Linger::C('SESSION'); Linger::getSessionHandler($session)->begin(); session_cache_limiter('private, must-revalidate'); //支持页面回跳 session_start(); }
/** * @return Linger\core\app */ public function bootstrap() { static::$bootstrap_func = get_class_methods(Linger::C('BOOTSTRAP_NAME')); $bootstrap = Linger::C('BOOTSTRAP_NAME'); $bootstrap = new $bootstrap(); foreach (static::$bootstrap_func as $func) { if (substr($func, 0, 4) === 'init') { call_user_func(array($bootstrap, $func), $this); } } return $this; }
/** * @param string $savePath * @param string $sessionName * * @return bool */ public function open($savePath, $sessionName) { if (!is_resource($this->_options['handler'])) { //连接redis $redisHandle = new \Redis(); $redisHandle->connect(Linger::C($this->_options['DRIVER'])['HOST'], Linger::C($this->_options['DRIVER'])['PORT']); if (!$redisHandle) { return false; } $this->_options['handler'] = $redisHandle; $this->gc(null); } return true; }
public static function mark($key, $num = 1) { self::conf(); $keys = self::keys($key); if ($keys === false) { return false; } $redisConf = Linger::C('redis.monitor'); $redis = new Redis(); try { $redis->connect($redisConf['host'], $redisConf['port'], 0.5); } catch (\Exception $e) { } $now = time(); if ($num > 0) { $redis->incrBy($keys['count'], $num); } else { $redis->incr($keys['count']); } $redis->set($keys['time'], $now); }