/
NativeMemcachedSessionStorage.php
76 lines (68 loc) · 2.08 KB
/
NativeMemcachedSessionStorage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Session\Storage;
/**
* NativeMemcachedSessionStorage.
*
* Session based on native PHP memcached database handler.
*
* @author Drak <drak@zikula.org>
*/
class NativeMemcachedSessionStorage extends AbstractSessionStorage
{
/**
* @var string
*/
private $savePath;
/**
* Constructor.
*
* @param string $savePath Comma separated list of servers: e.g. memcache1.example.com:11211,memcache2.example.com:11211
* @param array $options Session configuration options.
*
* @see AbstractSessionStorage::__construct()
*/
public function __construct($savePath = '127.0.0.1:11211', array $options = array())
{
if (!extension_loaded('memcached')) {
throw new \RuntimeException('PHP does not have "memcached" session module registered');
}
$this->savePath = $savePath;
parent::__construct($options);
}
/**
* {@inheritdoc}
*/
protected function registerSaveHandlers()
{
ini_set('session.save_handler', 'memcached');
ini_set('session.save_path', $this->savePath);
}
/**
* {@inheritdoc}
*
* Sets any values memcached ini values.
*
* @see https://github.com/php-memcached-dev/php-memcached/blob/master/memcached.ini
*/
protected function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array($key, array(
'memcached.sess_locking', 'memcached.sess_lock_wait',
'memcached.sess_prefix', 'memcached.compression_type',
'memcached.compression_factor', 'memcached.compression_threshold',
'memcached.serializer'))) {
ini_set($key, $value);
}
}
parent::setOptions($options);
}
}