Open Journal Systems  3.3.0
MemcacheSessionHandler.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
19 class MemcacheSessionHandler implements \SessionHandlerInterface
20 {
24  private $memcache;
25 
29  private $ttl;
30 
34  private $prefix;
35 
48  public function __construct(\Memcache $memcache, array $options = array())
49  {
50  if ($diff = array_diff(array_keys($options), array('prefix', 'expiretime'))) {
51  throw new \InvalidArgumentException(sprintf(
52  'The following options are not supported "%s"', implode(', ', $diff)
53  ));
54  }
55 
56  $this->memcache = $memcache;
57  $this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400;
58  $this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2s';
59  }
60 
64  public function open($savePath, $sessionName)
65  {
66  return true;
67  }
68 
72  public function close()
73  {
74  return true;
75  }
76 
80  public function read($sessionId)
81  {
82  return $this->memcache->get($this->prefix.$sessionId) ?: '';
83  }
84 
88  public function write($sessionId, $data)
89  {
90  return $this->memcache->set($this->prefix.$sessionId, $data, 0, time() + $this->ttl);
91  }
92 
96  public function destroy($sessionId)
97  {
98  return $this->memcache->delete($this->prefix.$sessionId);
99  }
100 
104  public function gc($maxlifetime)
105  {
106  // not required here because memcache will auto expire the records anyhow.
107  return true;
108  }
109 
115  protected function getMemcache()
116  {
117  return $this->memcache;
118  }
119 }
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\write
write($sessionId, $data)
Definition: MemcacheSessionHandler.php:97
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\gc
gc($maxlifetime)
Definition: MemcacheSessionHandler.php:113
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\read
read($sessionId)
Definition: MemcacheSessionHandler.php:89
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\__construct
__construct(\Memcache $memcache, array $options=array())
Definition: MemcacheSessionHandler.php:57
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\open
open($savePath, $sessionName)
Definition: MemcacheSessionHandler.php:73
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\close
close()
Definition: MemcacheSessionHandler.php:81
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\getMemcache
getMemcache()
Definition: MemcacheSessionHandler.php:124
Symfony\Component\HttpFoundation\Session\Storage\Handler
Definition: lib/vendor/symfony/http-foundation/Session/Storage/Handler/MemcachedSessionHandler.php:12
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler\destroy
destroy($sessionId)
Definition: MemcacheSessionHandler.php:105
Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
Definition: MemcacheSessionHandler.php:19