68 public static function read($id)
70 if(!self::isConnected() || !self::isValidId($id))
77 if (!self::$isReadOnly)
83 if (defined(
'BX_SECURITY_SESSION_REDIS_EXLOCK') && BX_SECURITY_SESSION_REDIS_EXLOCK)
85 $lock = Bitrix\Main\Context::getCurrent()->getRequest()->getRequestedPage();
92 while(!self::$connection->setnx($sid.$id.
'.lock', $lock))
95 $lockWait -= $waitStep;
98 $errorText =
'Unable to get session lock within 60 seconds.';
101 $lockedUri = self::$connection->get($sid.$id.
".lock");
102 if ($lockedUri && $lockedUri != 1)
103 $errorText .= sprintf(
' Locked by "%s".', $lockedUri);
109 if($waitStep < 1000000)
112 self::$connection->expire($sid.$id.
".lock", $lockTimeout);
115 self::$sessionId = $id;
116 self::$isSessionReady =
true;
117 $res = self::$connection->get($sid.$id);
121 if (!self::$hasFailedRead)
124 self::$hasFailedRead =
true;
256 if (!extension_loaded(
'redis'))
259 $exception = new \ErrorException(
"redis extention not loaded.", 0, E_USER_ERROR, __FILE__, __LINE__);
264 if (!self::isStorageEnabled())
267 $exception = new \ErrorException(
"BX_SECURITY_SESSION_REDIS_HOST constant is not defined.", 0, E_USER_ERROR, __FILE__, __LINE__);
273 $port = defined(
"BX_SECURITY_SESSION_REDIS_PORT")? intval(BX_SECURITY_SESSION_REDIS_PORT): 11211;
274 self::$connection = new \Redis();
275 $result = self::$connection->pconnect(BX_SECURITY_SESSION_REDIS_HOST, $port);
279 self::$connection->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_IGBINARY);
283 $error = error_get_last();
294 $exceptionHandler =
$application->getExceptionHandler();
295 $exceptionHandler->writeToLog($exception);