[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 12 namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; 13 14 /** 15 * Memcached based session storage handler based on the Memcached class 16 * provided by the PHP memcached extension. 17 * 18 * @see http://php.net/memcached 19 * 20 * @author Drak <drak@zikula.org> 21 */ 22 class MemcachedSessionHandler implements \SessionHandlerInterface 23 { 24 private $memcached; 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 memcached keys in order to avoid collision 41 * * expiretime: The time to live in seconds 42 * 43 * @param \Memcached $memcached A \Memcached instance 44 * @param array $options An associative array of Memcached options 45 * 46 * @throws \InvalidArgumentException When unsupported options are passed 47 */ 48 public function __construct(\Memcached $memcached, array $options = array()) 49 { 50 $this->memcached = $memcached; 51 52 if ($diff = array_diff(array_keys($options), array('prefix', 'expiretime'))) { 53 throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff))); 54 } 55 56 $this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400; 57 $this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2s'; 58 } 59 60 /** 61 * {@inheritdoc} 62 */ 63 public function open($savePath, $sessionName) 64 { 65 return true; 66 } 67 68 /** 69 * {@inheritdoc} 70 */ 71 public function close() 72 { 73 return true; 74 } 75 76 /** 77 * {@inheritdoc} 78 */ 79 public function read($sessionId) 80 { 81 return $this->memcached->get($this->prefix.$sessionId) ?: ''; 82 } 83 84 /** 85 * {@inheritdoc} 86 */ 87 public function write($sessionId, $data) 88 { 89 return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl); 90 } 91 92 /** 93 * {@inheritdoc} 94 */ 95 public function destroy($sessionId) 96 { 97 $result = $this->memcached->delete($this->prefix.$sessionId); 98 99 return $result || \Memcached::RES_NOTFOUND == $this->memcached->getResultCode(); 100 } 101 102 /** 103 * {@inheritdoc} 104 */ 105 public function gc($maxlifetime) 106 { 107 // not required here because memcached will auto expire the records anyhow. 108 return true; 109 } 110 111 /** 112 * Return a Memcached instance. 113 * 114 * @return \Memcached 115 */ 116 protected function getMemcached() 117 { 118 return $this->memcached; 119 } 120 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |