MemcachedHandler class

Framework\Session\SaveHandlers\MemcachedHandler

Class MemcachedHandler.

Extends Framework\Session\SaveHandler

Implements: SessionUpdateTimestampHandlerInterface, SessionHandlerInterface

Defined in libraries/session/src/SaveHandlers/MemcachedHandler.php

Properties #

$memcached
-

$memcached

protected ?Memcached $memcached

Methods #

close()
-
destroy()
-
gc()
-
getMemcached()
-
open()
-
read()
-
setMemcached()
-
updateTimestamp()
-
write()
-
getExpiration()
Get expiration as a timestamp.
getKey()
Get a key for Memcached, using the optional prefix, match IP and match User-Agent configs.
lock()
-
prepareConfig()
Prepare configurations to be used by the MemcachedHandler.
unlock()
-

close()

public function close(): bool
Returns bool

destroy()

public function destroy($id): bool
Parameters
  • $id
Returns bool

gc()

public function gc($max_lifetime): int|false
Parameters
  • $max_lifetime
Returns int|false

getMemcached()

public function getMemcached(): ?Memcached
Returns ?Memcached

open()

public function open($path, $name): bool
Parameters
  • $path
  • $name
Returns bool

read()

public function read($id): string
Parameters
  • $id
Returns string

setMemcached()

public function setMemcached(Memcached $memcached): static
Parameters
  • Memcached $memcached
Returns static

updateTimestamp()

public function updateTimestamp($id, $data): bool
Parameters
  • $id
  • $data
Returns bool

write()

public function write($id, $data): bool
Parameters
  • $id
  • $data
Returns bool

getExpiration()

protected function getExpiration(int $seconds): int

Get expiration as a timestamp.

Useful for Time To Live greater than a month (`60*60*24*30`).

Parameters
  • int $seconds
Returns int

getKey()

protected function getKey(string $id): string

Get a key for Memcached, using the optional prefix, match IP and match User-Agent configs.

NOTE: The max key length allowed by Memcached is 250 bytes.

Parameters
  • string $id - The session id
Returns string - The final key

lock()

protected function lock(string $id): bool
Parameters
  • string $id
Returns bool

prepareConfig()

protected function prepareConfig(array $config): void

Prepare configurations to be used by the MemcachedHandler.

Parameters
  • array $config - Custom configs The custom configs are: ```php $configs = [ // A custom prefix prepended in the keys 'prefix' => '', // A list of Memcached servers 'servers' => [ [ 'host' => '127.0.0.1', // host always is required 'port' => 11211, // port is optional, default to 11211 'weight' => 0, // weight is optional, default to 0 ], ], // An associative array of Memcached::OPT_* constants 'options' => [ Memcached::OPT_BINARY_PROTOCOL => true, ], // Maximum attempts to try lock a session id 'lock_attempts' => 60, // Interval between the lock attempts in microseconds 'lock_sleep' => 1_000_000, // TTL to the lock (valid for the current session only) 'lock_ttl' => 600, // The maxlifetime (TTL) used for cache item expiration 'maxlifetime' => null, // Null to use the ini value of session.gc_maxlifetime // Match IP? 'match_ip' => false, // Match User-Agent? 'match_ua' => false, ]; ```
Returns void

unlock()

protected function unlock(): bool
Returns bool

Inherited methods #