setCloseOnDestruct() public method

public setCloseOnDestruct ( boolean $flag ) : Credis_Client
$flag boolean
return Credis_Client
 public function __construct()
 {
     $this->_timeStart = microtime(true);
     $host = (string) (Mage::getConfig()->getNode(self::XML_PATH_HOST) ?: '127.0.0.1');
     $port = (int) (Mage::getConfig()->getNode(self::XML_PATH_PORT) ?: '6379');
     $pass = (string) (Mage::getConfig()->getNode(self::XML_PATH_PASS) ?: '');
     $timeout = (double) (Mage::getConfig()->getNode(self::XML_PATH_TIMEOUT) ?: self::DEFAULT_TIMEOUT);
     $persistent = (string) (Mage::getConfig()->getNode(self::XML_PATH_PERSISTENT) ?: '');
     $this->_dbNum = (int) (Mage::getConfig()->getNode(self::XML_PATH_DB) ?: 0);
     $this->_compressionThreshold = (int) (Mage::getConfig()->getNode(self::XML_PATH_COMPRESSION_THRESHOLD) ?: self::DEFAULT_COMPRESSION_THRESHOLD);
     $this->_compressionLib = (string) (Mage::getConfig()->getNode(self::XML_PATH_COMPRESSION_LIB) ?: self::DEFAULT_COMPRESSION_LIB);
     $this->_logLevel = (int) (Mage::getConfig()->getNode(self::XML_PATH_LOG_LEVEL) ?: self::DEFAULT_LOG_LEVEL);
     $this->_maxConcurrency = (int) (Mage::getConfig()->getNode(self::XML_PATH_MAX_CONCURRENCY) ?: self::DEFAULT_MAX_CONCURRENCY);
     $this->_breakAfter = (int) (Mage::getConfig()->getNode(sprintf(self::XML_PATH_BREAK_AFTER, session_name())) ?: self::DEFAULT_BREAK_AFTER);
     $this->_botLifetime = (int) (Mage::getConfig()->getNode(self::XML_PATH_BOT_LIFETIME) ?: self::DEFAULT_BOT_LIFETIME);
     if ($this->_botLifetime) {
         $userAgent = empty($_SERVER['HTTP_USER_AGENT']) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
         $this->_isBot = !$userAgent || preg_match(self::BOT_REGEX, $userAgent);
     }
     $this->_redis = new Credis_Client($host, $port, $timeout, $persistent);
     if (!empty($pass)) {
         $this->_redis->auth($pass) or Zend_Cache::throwException('Unable to authenticate with the redis server.');
     }
     $this->_redis->setCloseOnDestruct(FALSE);
     // Destructor order cannot be predicted
     $this->_useRedis = TRUE;
     if ($this->_logLevel >= 7) {
         Mage::log(sprintf("%s: %s initialized for connection to %s:%s after %.5f seconds", $this->_getPid(), get_class($this), $host, $port, microtime(true) - $this->_timeStart), Zend_Log::DEBUG, self::LOG_FILE);
         if ($this->_isBot) {
             Mage::log(sprintf("%s: Bot detected for user agent: %s", $this->_getPid(), $userAgent), Zend_Log::DEBUG, self::LOG_FILE);
         }
     }
 }
Beispiel #2
0
 /**
  * @param Handler\ConfigInterface $config
  * @param Handler\LoggerInterface $logger
  * @param Handler\ProfilerInterface|null $profiler
  */
 public function __construct(\Cm\RedisSession\Handler\ConfigInterface $config, \Cm\RedisSession\Handler\LoggerInterface $logger, \Cm\RedisSession\Handler\ProfilerInterface $profiler = null)
 {
     $this->_config = $config;
     $this->logger = $logger;
     $this->profiler = $profiler;
     $this->_logLevel = (int) ($config->descend('log_level') ?: self::DEFAULT_LOG_LEVEL);
     if ($this->_logLevel >= \Zend_Log::DEBUG) {
         $timeStart = microtime(true);
     }
     // Database config
     $host = "{$config->descend('host')}" ?: '127.0.0.1';
     $port = (int) $config->descend('port') ?: 6379;
     $pass = (string) ($config->descend('password') ?: '');
     $timeout = (double) ($config->descend('timeout') ?: self::DEFAULT_TIMEOUT);
     $persistent = (string) ($config->descend('persistent') ?: '');
     $this->_dbNum = (int) ($config->descend('db') ?: 0);
     // General config
     $this->_compressionThreshold = (int) ($config->descend('compression_threshold') ?: self::DEFAULT_COMPRESSION_THRESHOLD);
     $this->_compressionLib = (string) ($config->descend('compression_lib') ?: self::DEFAULT_COMPRESSION_LIB);
     $this->_maxConcurrency = (int) ($config->descend('max_concurrency') ?: self::DEFAULT_MAX_CONCURRENCY);
     $this->_maxLifetime = (int) ($config->descend('max_lifetime') ?: self::DEFAULT_MAX_LIFETIME);
     $this->_minLifetime = (int) ($config->descend('min_lifetime') ?: self::DEFAULT_MIN_LIFETIME);
     $this->_useLocking = defined('CM_REDISSESSION_LOCKING_ENABLED') ? CM_REDISSESSION_LOCKING_ENABLED : !(strlen("{$config->descend('disable_locking')}") ? (bool) "{$config->descend('disable_locking')}" : self::DEFAULT_DISABLE_LOCKING);
     // Use sleep time multiplier so break time is in seconds
     $this->_failAfter = (int) round(1000000 / self::SLEEP_TIME * self::FAIL_AFTER);
     // Connect and authenticate
     $this->_redis = new \Credis_Client($host, $port, $timeout, $persistent);
     if (!empty($pass)) {
         $this->_redis->auth($pass) or \Zend_Cache::throwException('Unable to authenticate with the redis server.');
     }
     $this->_redis->setCloseOnDestruct(FALSE);
     // Destructor order cannot be predicted
     if ($this->_logLevel >= \Zend_Log::DEBUG) {
         $this->_log(sprintf("%s initialized for connection to %s:%s after %.5f seconds", get_class($this), $host, $port, microtime(true) - $timeStart));
     }
 }
Beispiel #3
0
 public function __construct()
 {
     $this->_config = $config = Mage::getConfig()->getNode('global/redis_session');
     if (!$config) {
         $this->_useRedis = FALSE;
         Mage::log('Redis configuration does not exist, falling back to MySQL handler.', Zend_Log::EMERG);
         parent::__construct();
         return;
     }
     $this->_logLevel = (int) ($config->descend('log_level') ?: self::DEFAULT_LOG_LEVEL);
     if ($this->_logLevel >= Zend_Log::DEBUG) {
         $timeStart = microtime(true);
     }
     // Database config
     $host = "{$config->descend('host')}" ?: '127.0.0.1';
     $port = (int) $config->descend('port') ?: 6379;
     $pass = (string) ($config->descend('password') ?: '');
     $timeout = (double) ($config->descend('timeout') ?: self::DEFAULT_TIMEOUT);
     $persistent = (string) ($config->descend('persistent') ?: '');
     $this->_dbNum = (int) ($config->descend('db') ?: 0);
     // General config
     $this->_compressionThreshold = (int) ($config->descend('compression_threshold') ?: self::DEFAULT_COMPRESSION_THRESHOLD);
     $this->_compressionLib = (string) ($config->descend('compression_lib') ?: self::DEFAULT_COMPRESSION_LIB);
     $this->_maxConcurrency = (int) ($config->descend('max_concurrency') ?: self::DEFAULT_MAX_CONCURRENCY);
     $this->_maxLifetime = (int) ($config->descend('max_lifetime') ?: self::DEFAULT_MAX_LIFETIME);
     $this->_minLifetime = (int) ($config->descend('min_lifetime') ?: self::DEFAULT_MIN_LIFETIME);
     $this->_useLocking = defined('CM_REDISSESSION_LOCKING_ENABLED') ? CM_REDISSESSION_LOCKING_ENABLED : !(strlen("{$config->descend('disable_locking')}") ? (bool) "{$config->descend('disable_locking')}" : self::DEFAULT_DISABLE_LOCKING);
     // Use sleep time multiplier so break time is in seconds
     $this->_failAfter = (int) round(1000000 / self::SLEEP_TIME * self::FAIL_AFTER);
     // Connect and authenticate
     $this->_redis = new Credis_Client($host, $port, $timeout, $persistent);
     if (!empty($pass)) {
         $this->_redis->auth($pass) or Zend_Cache::throwException('Unable to authenticate with the redis server.');
     }
     $this->_redis->setCloseOnDestruct(FALSE);
     // Destructor order cannot be predicted
     $this->_useRedis = TRUE;
     if ($this->_logLevel >= Zend_Log::DEBUG) {
         $this->_log(sprintf("%s initialized for connection to %s:%s after %.5f seconds", get_class($this), $host, $port, microtime(true) - $timeStart));
     }
 }
Beispiel #4
0
 /**
  * @param ConfigInterface $config
  * @param LoggerInterface $logger
  * @throws ConnectionFailedException
  */
 public function __construct(ConfigInterface $config, LoggerInterface $logger)
 {
     $this->config = $config;
     $this->logger = $logger;
     $this->logger->setLogLevel($this->config->getLogLevel() ?: self::DEFAULT_LOG_LEVEL);
     $timeStart = microtime(true);
     // Database config
     $host = $this->config->getHost() ?: self::DEFAULT_HOST;
     $port = $this->config->getPort() ?: self::DEFAULT_PORT;
     $pass = $this->config->getPassword() ?: null;
     $timeout = $this->config->getTimeout() ?: self::DEFAULT_TIMEOUT;
     $persistent = $this->config->getPersistentIdentifier() ?: '';
     $this->_dbNum = $this->config->getDatabase() ?: self::DEFAULT_DATABASE;
     // General config
     $this->_compressionThreshold = $this->config->getCompressionThreshold() ?: self::DEFAULT_COMPRESSION_THRESHOLD;
     $this->_compressionLibrary = $this->config->getCompressionLibrary() ?: self::DEFAULT_COMPRESSION_LIBRARY;
     $this->_maxConcurrency = $this->config->getMaxConcurrency() ?: self::DEFAULT_MAX_CONCURRENCY;
     $this->_maxLifetime = $this->config->getMaxLifetime() ?: self::DEFAULT_MAX_LIFETIME;
     $this->_minLifetime = $this->config->getMinLifetime() ?: self::DEFAULT_MIN_LIFETIME;
     $this->_useLocking = $this->config->getDisableLocking() ?: self::DEFAULT_DISABLE_LOCKING;
     // Use sleep time multiplier so break time is in seconds
     $this->_failAfter = (int) round(1000000 / self::SLEEP_TIME * self::FAIL_AFTER);
     // Connect and authenticate
     $this->_redis = new \Credis_Client($host, $port, $timeout, $persistent, 0, $pass);
     if ($this->hasConnection() == false) {
         throw new ConnectionFailedException('Unable to connect to Redis');
     }
     // Destructor order cannot be predicted
     $this->_redis->setCloseOnDestruct(false);
     $this->_log(sprintf("%s initialized for connection to %s:%s after %.5f seconds", get_class($this), $host, $port, microtime(true) - $timeStart));
 }