Ejemplo n.º 1
0
 /**
  * @param string $id - session id, must be valid hash
  * @return string
  */
 public static function read($id)
 {
     if (!self::isConnected() || !self::isValidId($id)) {
         return "";
     }
     $sid = self::getPrefix();
     if (!self::$isReadOnly) {
         $lockTimeout = 55;
         //TODO: add setting
         $lockWait = 59000000;
         //micro seconds = 60 seconds TODO: add setting
         $waitStep = 100;
         while (!self::$connection->add($sid . $id . ".lock", 1, 0, $lockTimeout)) {
             usleep($waitStep);
             $lockWait -= $waitStep;
             if ($lockWait < 0) {
                 CSecuritySession::triggerFatalError('Unable to get session lock within 60 seconds.');
             }
             if ($waitStep < 1000000) {
                 $waitStep *= 2;
             }
         }
     }
     self::$sessionId = $id;
     $res = self::$connection->get($sid . $id);
     if ($res === false) {
         $res = "";
     }
     return $res;
 }
Ejemplo n.º 2
0
	/**
	 * @param string $id - session id, must be valid hash
	 * @return string
	 */
	public static function read($id)
	{
		if(!self::isConnected() || !self::isValidId($id))
			return "";

		$sid = self::getPrefix();

		if (!self::$isReadOnly)
		{
			$lockTimeout = 55;//TODO: add setting
			$lockWait = 59000000;//micro seconds = 60 seconds TODO: add setting
			$waitStep = 100;

			if (defined('BX_SECURITY_SESSION_MEMCACHE_EXLOCK') && BX_SECURITY_SESSION_MEMCACHE_EXLOCK)
				$lock = Bitrix\Main\Context::getCurrent()->getRequest()->getRequestedPage();
			else
				$lock = 1;

			while(!self::$connection->add($sid.$id.".lock", $lock, 0, $lockTimeout))
			{
				usleep($waitStep);
				$lockWait -= $waitStep;
				if($lockWait < 0)
				{
					$errorText = 'Unable to get session lock within 60 seconds.';
					if ($lock !== 1)
					{
						$lockedUri = self::$connection->get($sid.$id.".lock");
						if ($lockedUri && $lockedUri != 1)
							$errorText .= sprintf(' Locked by "%s".', self::$connection->get($sid.$id.".lock"));
					}

					CSecuritySession::triggerFatalError($errorText);
				}

				if($waitStep < 1000000)
					$waitStep *= 2;
			}
		}

		self::$sessionId = $id;
		self::$isSessionReady = true;
		$res = self::$connection->get($sid.$id);
		if($res === false)
			$res = "";

		return $res;
	}