示例#1
0
 /**
  * Update session
  *
  * @param string $sessionId
  * @param string $sessionData
  * @return boolean
  */
 public function write($sessionId, $sessionData)
 {
     Varien_Profiler::start(__METHOD__);
     if (!$this->_useRedis) {
         return parent::write($sessionId, $sessionData);
     }
     if ($this->_sessionWritten) {
         if ($this->_logLevel >= Zend_Log::DEBUG) {
             $this->_log(sprintf("Repeated session write detected; skipping for ID %s", $sessionId));
         }
         Varien_Profiler::stop(__METHOD__);
         return TRUE;
     }
     $this->_sessionWritten = TRUE;
     if ($this->_logLevel >= Zend_Log::WARN) {
         $timeStart = microtime(true);
     }
     // Do not overwrite the session if it is locked by another pid
     try {
         if ($this->_dbNum) {
             $this->_redis->select($this->_dbNum);
         }
         // Prevent conflicts with other connections?
         if (!$this->_useLocking || (!($pid = $this->_redis->hGet('sess_' . $sessionId, 'pid')) || $pid == $this->_getPid())) {
             $this->_writeRawSession($sessionId, $sessionData, $this->getLifeTime());
             if ($this->_logLevel >= Zend_Log::DEBUG) {
                 $this->_log(sprintf("Data written to ID %s in %.5f seconds", $sessionId, microtime(true) - $timeStart));
             }
         } else {
             if ($this->_logLevel >= Zend_Log::WARN) {
                 if ($this->_hasLock) {
                     $this->_log(sprintf("Did not write session for ID %s: another process took the lock.", $sessionId), Zend_Log::WARN);
                 } else {
                     $this->_log(sprintf("Did not write session for ID %s: unable to acquire lock.", $sessionId), Zend_Log::WARN);
                 }
             }
         }
     } catch (Exception $e) {
         if (class_exists('Mage', false)) {
             Mage::logException($e);
         } else {
             error_log("{$e}");
         }
         Varien_Profiler::stop(__METHOD__);
         return FALSE;
     }
     Varien_Profiler::stop(__METHOD__);
     return TRUE;
 }
 /**
  * Update session
  *
  * @param string $sessionId
  * @param string $sessionData
  * @return boolean
  */
 public function write($sessionId, $sessionData)
 {
     if (!$this->_useRedis) {
         return parent::write($sessionId, $sessionData);
     }
     if ($this->_sessionWritten) {
         if ($this->_logLevel >= 7) {
             Mage::log(sprintf("%s: Repeated session write detected; skipping for ID %s", $this->_getPid(), $sessionId), Zend_Log::DEBUG, self::LOG_FILE);
         }
         return TRUE;
     }
     $this->_sessionWritten = TRUE;
     if ($this->_logLevel >= 7) {
         Mage::log(sprintf("%s: Attempting write to ID %s", $this->_getPid(), $sessionId), Zend_Log::DEBUG, self::LOG_FILE);
         // reset timer
         $this->_timeStart = microtime(true);
     }
     // Do not overwrite the session if it is locked by another pid
     try {
         if ($this->_dbNum) {
             $this->_redis->select($this->_dbNum);
         }
         // Prevent conflicts with other connections?
         $pid = $this->_redis->hGet('sess_' . $sessionId, 'pid');
         // PHP Fatal errors cause self::SESSION_PREFIX to not work..
         if (!$pid || $pid == $this->_getPid()) {
             if ($this->_logLevel >= 7) {
                 Mage::log(sprintf("%s: Write lock obtained on ID %s", $this->_getPid(), $sessionId), Zend_Log::DEBUG, self::LOG_FILE);
             }
             $this->_writeRawSession($sessionId, $sessionData, $this->getLifeTime());
             if ($this->_logLevel >= 7) {
                 Mage::log(sprintf("%s: Data written to ID %s after %.5f seconds", $this->_getPid(), $sessionId, microtime(true) - $this->_timeStart), Zend_Log::DEBUG, self::LOG_FILE);
             }
         } else {
             if ($this->_logLevel >= 4) {
                 if ($this->_hasLock) {
                     Mage::log(sprintf("%s: Unable to write session after %.5f seconds, another process took the lock for ID %s", $this->_getPid(), microtime(true) - $this->_timeStart, $sessionId), Zend_Log::WARN, self::LOG_FILE);
                 } else {
                     Mage::log(sprintf("%s: Unable to write session after %.5f seconds, unable to acquire lock on ID %s", $this->_getPid(), microtime(true) - $this->_timeStart, $sessionId), Zend_Log::WARN, self::LOG_FILE);
                 }
             }
         }
     } catch (Exception $e) {
         if (class_exists('Mage', false)) {
             Mage::logException($e);
         } else {
             error_log("{$e}");
         }
         return FALSE;
     }
     return TRUE;
 }