-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
NativeMemcacheSessionStorage.php
82 lines (73 loc) · 2.55 KB
/
NativeMemcacheSessionStorage.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
77
78
79
80
81
82
<?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\SessionStorage;
use Symfony\Component\HttpFoundation\AttributeBagInterface;
use Symfony\Component\HttpFoundation\FlashBagInterface;
/**
* NativeMemcacheSessionStorage.
*
* Session based on native PHP memcache database handler.
*
* @author Drak <drak@zikula.org>
*/
class NativeMemcacheSessionStorage extends AbstractSessionStorage
{
/**
* @var string
*/
private $savePath;
/**
* Constructor.
*
* @param string $savePath Path of memcache server.
* @param array $options Session configuration options.
* @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
* @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
*
* @see AbstractSessionStorage::__construct()
*/
public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
{
if (!extension_loaded('memcache')) {
throw new \RuntimeException('PHP does not have "memcache" session module registered');
}
$this->savePath = $savePath;
parent::__construct($attributes, $flashes, $options);
}
/**
* {@inheritdoc}
*/
protected function registerSaveHandlers()
{
ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', $this->savePath);
}
/**
* {@inheritdoc}
*
* Sets any values memcached ini values.
*
* @see http://www.php.net/manual/en/memcache.ini.php
*/
protected function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array($key, array(
'memcache.allow_failover', 'memcache.max_failover_attempts',
'memcache.chunk_size', 'memcache.default_port', 'memcache.hash_strategy',
'memcache.hash_function', 'memcache.protocol', 'memcache.redundancy',
'memcache.session_redundancy', 'memcache.compress_threshold',
'memcache.lock_timeout'))) {
ini_set($key, $value);
}
}
parent::setOptions($options);
}
}