Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ public static function createConnection($servers, array $options = [])
if ('HASH' === $name || 'SERIALIZER' === $name || 'DISTRIBUTION' === $name) {
$value = \constant('Memcached::'.$name.'_'.strtoupper($value));
}
$opt = \constant('Memcached::OPT_'.$name);

unset($options[$name]);
$options[$opt] = $value;

if (\defined('Memcached::OPT_'.$name)) {
$options[\constant('Memcached::OPT_'.$name)] = $value;
}
}
$client->setOptions($options);

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Deprecate passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()`, pass an empty string instead.
* Add the `litespeed_finish_request` method to work with Litespeed
* Deprecate `upload_progress.*` and `url_rewriter.tags` session options
* Allow setting session options via DSN

5.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ class MemcachedSessionHandler extends AbstractSessionHandler
*
* List of available options:
* * prefix: The prefix to use for the memcached keys in order to avoid collision
* * expiretime: The time to live in seconds.
* * ttl: The time to live in seconds.
*
* @throws \InvalidArgumentException When unsupported options are passed
*/
public function __construct(\Memcached $memcached, array $options = [])
{
$this->memcached = $memcached;

if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime'])) {
if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime', 'ttl'])) {
throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff)));
}

$this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400;
$this->ttl = $options['expiretime'] ?? $options['ttl'] ?? null;
$this->prefix = $options['prefix'] ?? 'sf2s';
}

Expand All @@ -77,7 +77,7 @@ protected function doRead(string $sessionId)
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
$this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl);
$this->memcached->touch($this->prefix.$sessionId, time() + (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')));

return true;
}
Expand All @@ -87,7 +87,7 @@ public function updateTimestamp($sessionId, $data)
*/
protected function doWrite(string $sessionId, string $data)
{
return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
return $this->memcached->set($this->prefix.$sessionId, $data, time() + (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public static function createHandler($connection): AbstractSessionHandler
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, get_debug_type($connection)));
}

if ($options = parse_url($connection)) {
parse_str($options['query'] ?? '', $options);
}

switch (true) {
case $connection instanceof \Redis:
case $connection instanceof \RedisArray:
Expand Down Expand Up @@ -61,7 +65,7 @@ public static function createHandler($connection): AbstractSessionHandler
$handlerClass = str_starts_with($connection, 'memcached:') ? MemcachedSessionHandler::class : RedisSessionHandler::class;
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);

return new $handlerClass($connection);
return new $handlerClass($connection, array_intersect_key($options ?: [], ['prefix' => 1, 'ttl' => 1]));

case str_starts_with($connection, 'pdo_oci://'):
if (!class_exists(DriverManager::class)) {
Expand All @@ -79,7 +83,7 @@ public static function createHandler($connection): AbstractSessionHandler
case str_starts_with($connection, 'sqlsrv://'):
case str_starts_with($connection, 'sqlite://'):
case str_starts_with($connection, 'sqlite3://'):
return new PdoSessionHandler($connection);
return new PdoSessionHandler($connection, $options ?: []);
}

throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
Expand Down