3namespace Bitrix\Main\Session\Handlers;
5use Bitrix\Main\Application;
6use Bitrix\Main\Context;
7use Bitrix\Main\Data\RedisConnection;
20 $this->readOnly =
$options[
'readOnly'] ??
false;
21 $this->prefix =
$options[
'keyPrefix'] ??
'BX';
22 $this->exclusiveLock =
$options[
'exclusiveLock'] ??
false;
25 $port = (int)(
$options[
'port'] ?? 6379);
26 if (str_starts_with(
$host,
'unix://'))
32 $connectionPool->setConnectionParameters(self::SESSION_REDIS_CONNECTION, [
33 'className' => RedisConnection::class,
36 'servers' =>
$options[
'servers'] ?? [],
37 'serializer' =>
$options[
'serializer'] ??
null,
38 'failover' =>
$options[
'failover'] ??
null,
39 'timeout' =>
$options[
'timeout'] ??
null,
40 'readTimeout' =>
$options[
'readTimeout'] ??
null,
41 'persistent' =>
$options[
'persistent'] ??
null,
45 public function open($savePath, $sessionName): bool
47 return $this->createConnection();
67 $maxLifetime = (int)ini_get(
"session.gc_maxlifetime");
76 $isConnectionRestored =
false;
79 $isConnectionRestored = $this->createConnection();
89 if ($isConnectionRestored)
97 public function gc($maxLifeTime): int
104 return $this->connection !==
null;
112 protected function createConnection(): bool
116 $redisConnection = $connectionPool->getConnection(self::SESSION_REDIS_CONNECTION);
117 if (!$redisConnection)
122 $this->connection = $redisConnection->getResource();
124 return $redisConnection->isConnected();
131 $this->connection->close();
134 $this->connection =
null;
146 $lockWait = 59000000;
150 if ($this->exclusiveLock)
152 $lock = Context::getCurrent()->getRequest()->getRequestedPage();
155 while (!$this->connection->setnx($sid .
$sessionId .
".lock", $lock))
158 $lockWait -= $waitStep;
164 $lockedUri = $this->connection->get($sid .
$sessionId .
".lock");
165 if ($lockedUri && $lockedUri != 1)
167 $errorText .= sprintf(
' Locked by "%s".', $lockedUri);
174 if ($waitStep < 1000000)
179 $this->connection->expire($sid .
$sessionId .
".lock", $lockTimeout);
186 $this->connection->del($this->
getPrefix() .
"{$sessionId}.lock");
triggerLockFatalError(string $additionalText='')
write($sessionId, $sessionData)
__construct(array $options)
processWrite($sessionId, $sessionData)
updateTimestamp($sessionId, $sessionData)
processDestroy($sessionId)
open($savePath, $sessionName)
const SESSION_REDIS_CONNECTION
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)