2011-12-04 11:49:10 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2012-02-08 23:15:47 +00:00
|
|
|
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
2011-12-04 11:49:10 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-11 11:04:05 +00:00
|
|
|
* NativeMemcachedSessionStorage.
|
2011-12-04 11:49:10 +00:00
|
|
|
*
|
|
|
|
* Session based on native PHP memcached database handler.
|
|
|
|
*
|
|
|
|
* @author Drak <drak@zikula.org>
|
|
|
|
*/
|
2012-02-11 11:04:05 +00:00
|
|
|
class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
2011-12-04 11:49:10 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
2012-02-11 11:04:05 +00:00
|
|
|
* @see AbstractSessionStorage::__construct()
|
2011-12-04 11:49:10 +00:00
|
|
|
*/
|
2012-02-08 09:46:38 +00:00
|
|
|
public function __construct($savePath = '127.0.0.1:11211', array $options = array())
|
2011-12-04 11:49:10 +00:00
|
|
|
{
|
2012-01-02 15:32:41 +00:00
|
|
|
if (!extension_loaded('memcached')) {
|
2011-12-04 11:49:10 +00:00
|
|
|
throw new \RuntimeException('PHP does not have "memcached" session module registered');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->savePath = $savePath;
|
2012-02-08 09:46:38 +00:00
|
|
|
parent::__construct($options);
|
2011-12-04 11:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function registerSaveHandlers()
|
|
|
|
{
|
2012-01-02 15:32:41 +00:00
|
|
|
ini_set('session.save_handler', 'memcached');
|
2011-12-04 11:49:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|