Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • MemcachedSessionHandler
  • MemcacheSessionHandler
  • MongoDbSessionHandler
  • NativeFileSessionHandler
  • NativeSessionHandler
  • NullSessionHandler
  • PdoSessionHandler
  • WriteCheckSessionHandler
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /*
  4:  * This file is part of the Symfony package.
  5:  *
  6:  * (c) Fabien Potencier <[email protected]>
  7:  *
  8:  * For the full copyright and license information, please view the LICENSE
  9:  * file that was distributed with this source code.
 10:  */
 11: 
 12: namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
 13: 
 14: /**
 15:  * MemcacheSessionHandler.
 16:  *
 17:  * @author Drak <[email protected]>
 18:  */
 19: class MemcacheSessionHandler implements \SessionHandlerInterface
 20: {
 21:     /**
 22:      * @var \Memcache Memcache driver
 23:      */
 24:     private $memcache;
 25: 
 26:     /**
 27:      * @var int Time to live in seconds
 28:      */
 29:     private $ttl;
 30: 
 31:     /**
 32:      * @var string Key prefix for shared environments
 33:      */
 34:     private $prefix;
 35: 
 36:     /**
 37:      * Constructor.
 38:      *
 39:      * List of available options:
 40:      *  * prefix: The prefix to use for the memcache keys in order to avoid collision
 41:      *  * expiretime: The time to live in seconds
 42:      *
 43:      * @param \Memcache $memcache A \Memcache instance
 44:      * @param array     $options  An associative array of Memcache options
 45:      *
 46:      * @throws \InvalidArgumentException When unsupported options are passed
 47:      */
 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: 
 61:     /**
 62:      * {@inheritdoc}
 63:      */
 64:     public function open($savePath, $sessionName)
 65:     {
 66:         return true;
 67:     }
 68: 
 69:     /**
 70:      * {@inheritdoc}
 71:      */
 72:     public function close()
 73:     {
 74:         return true;
 75:     }
 76: 
 77:     /**
 78:      * {@inheritdoc}
 79:      */
 80:     public function read($sessionId)
 81:     {
 82:         return $this->memcache->get($this->prefix.$sessionId) ?: '';
 83:     }
 84: 
 85:     /**
 86:      * {@inheritdoc}
 87:      */
 88:     public function write($sessionId, $data)
 89:     {
 90:         return $this->memcache->set($this->prefix.$sessionId, $data, 0, time() + $this->ttl);
 91:     }
 92: 
 93:     /**
 94:      * {@inheritdoc}
 95:      */
 96:     public function destroy($sessionId)
 97:     {
 98:         $this->memcache->delete($this->prefix.$sessionId);
 99: 
100:         return true;
101:     }
102: 
103:     /**
104:      * {@inheritdoc}
105:      */
106:     public function gc($maxlifetime)
107:     {
108:         // not required here because memcache will auto expire the records anyhow.
109:         return true;
110:     }
111: 
112:     /**
113:      * Return a Memcache instance.
114:      *
115:      * @return \Memcache
116:      */
117:     protected function getMemcache()
118:     {
119:         return $this->memcache;
120:     }
121: }
122: 
Ratchet API documentation generated by ApiGen 2.8.0