Пример #1
0
 /**
  * Get lock lifetime
  *
  * @return int|mixed
  */
 private function getLifeTime()
 {
     if (is_null($this->_lifeTime)) {
         $lifeTime = null;
         // Detect bots by user agent
         $botLifetime = $this->config->getBotLifetime() ?: self::DEFAULT_BOT_LIFETIME;
         if ($botLifetime) {
             $userAgent = empty($_SERVER['HTTP_USER_AGENT']) ? false : $_SERVER['HTTP_USER_AGENT'];
             $isBot = !$userAgent || preg_match(self::BOT_REGEX, $userAgent);
             if ($isBot) {
                 $this->_log(sprintf("Bot detected for user agent: %s", $userAgent));
                 if ($this->_sessionWrites <= 1 && ($botFirstLifetime = $this->config->getBotFirstLifetime() ?: self::DEFAULT_BOT_FIRST_LIFETIME)) {
                     $lifeTime = $botFirstLifetime * (1 + $this->_sessionWrites);
                 } else {
                     $lifeTime = $botLifetime;
                 }
             }
         }
         // Use different lifetime for first write
         if ($lifeTime === null && $this->_sessionWrites <= 1) {
             $firstLifetime = $this->config->getFirstLifetime() ?: self::DEFAULT_FIRST_LIFETIME;
             if ($firstLifetime) {
                 $lifeTime = $firstLifetime * (1 + $this->_sessionWrites);
             }
         }
         // Neither bot nor first write
         if ($lifeTime === null) {
             $this->_lifeTime = self::DEFAULT_LIFETIME;
         }
         if ($this->_lifeTime < $this->_minLifetime) {
             $this->_lifeTime = $this->_minLifetime;
         }
         if ($this->_lifeTime > $this->_maxLifetime) {
             $this->_lifeTime = $this->_maxLifetime;
         }
     }
     return $this->_lifeTime;
 }