Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

MemcacheSessionHandler.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 2.70 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
 013   
 014  /**
 015   * MemcacheSessionHandler.
 016   *
 017   * @author Drak <drak@zikula.org>
 018   */
 019  class MemcacheSessionHandler implements \SessionHandlerInterface
 020  {
 021      /**
 022       * @var \Memcache Memcache driver
 023       */
 024      private $memcache;
 025   
 026      /**
 027       * @var int Time to live in seconds
 028       */
 029      private $ttl;
 030   
 031      /**
 032       * @var string Key prefix for shared environments
 033       */
 034      private $prefix;
 035   
 036      /**
 037       * Constructor.
 038       *
 039       * List of available options:
 040       *  * prefix: The prefix to use for the memcache keys in order to avoid collision
 041       *  * expiretime: The time to live in seconds
 042       *
 043       * @param \Memcache $memcache A \Memcache instance
 044       * @param array     $options  An associative array of Memcache options
 045       *
 046       * @throws \InvalidArgumentException When unsupported options are passed
 047       */
 048      public function __construct(\Memcache $memcache, array $options = array())
 049      {
 050          if ($diff = array_diff(array_keys($options), array('prefix', 'expiretime'))) {
 051              throw new \InvalidArgumentException(sprintf(
 052                  'The following options are not supported "%s"', implode(', ', $diff)
 053              ));
 054          }
 055   
 056          $this->memcache = $memcache;
 057          $this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400;
 058          $this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2s';
 059      }
 060   
 061      /**
 062       * {@inheritdoc}
 063       */
 064      public function open($savePath, $sessionName)
 065      {
 066          return true;
 067      }
 068   
 069      /**
 070       * {@inheritdoc}
 071       */
 072      public function close()
 073      {
 074          return true;
 075      }
 076   
 077      /**
 078       * {@inheritdoc}
 079       */
 080      public function read($sessionId)
 081      {
 082          return $this->memcache->get($this->prefix.$sessionId) ?: '';
 083      }
 084   
 085      /**
 086       * {@inheritdoc}
 087       */
 088      public function write($sessionId, $data)
 089      {
 090          return $this->memcache->set($this->prefix.$sessionId, $data, 0, time() + $this->ttl);
 091      }
 092   
 093      /**
 094       * {@inheritdoc}
 095       */
 096      public function destroy($sessionId)
 097      {
 098          return $this->memcache->delete($this->prefix.$sessionId);
 099      }
 100   
 101      /**
 102       * {@inheritdoc}
 103       */
 104      public function gc($maxlifetime)
 105      {
 106          // not required here because memcache will auto expire the records anyhow.
 107          return true;
 108      }
 109   
 110      /**
 111       * Return a Memcache instance.
 112       *
 113       * @return \Memcache
 114       */
 115      protected function getMemcache()
 116      {
 117          return $this->memcache;
 118      }
 119  }
 120