Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

memcached.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.06 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\cache\driver;
015   
016  if (!defined('PHPBB_ACM_MEMCACHED_PORT'))
017  {
018      define('PHPBB_ACM_MEMCACHED_PORT', 11211);
019  }
020   
021  if (!defined('PHPBB_ACM_MEMCACHED_COMPRESS'))
022  {
023      define('PHPBB_ACM_MEMCACHED_COMPRESS', true);
024  }
025   
026  if (!defined('PHPBB_ACM_MEMCACHED_HOST'))
027  {
028      define('PHPBB_ACM_MEMCACHED_HOST', 'localhost');
029  }
030   
031  if (!defined('PHPBB_ACM_MEMCACHED'))
032  {
033      //can define multiple servers with host1/port1,host2/port2 format
034      define('PHPBB_ACM_MEMCACHED', PHPBB_ACM_MEMCACHED_HOST . '/' . PHPBB_ACM_MEMCACHED_PORT);
035  }
036   
037  /**
038  * ACM for Memcached
039  */
040  class memcached extends \phpbb\cache\driver\memory
041  {
042      /** @var string Extension to use */
043      protected $extension = 'memcached';
044   
045      /** @var \Memcached Memcached class */
046      protected $memcached;
047   
048      /** @var int Flags */
049      protected $flags = 0;
050   
051      /**
052       * Memcached constructor
053       *
054       * @param string $memcached_servers Memcached servers string (optional)
055       */
056      public function __construct($memcached_servers = '')
057      {
058          // Call the parent constructor
059          parent::__construct();
060   
061          $memcached_servers = $memcached_servers ?: PHPBB_ACM_MEMCACHED;
062   
063          $this->memcached = new \Memcached();
064          $this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
065          // Memcached defaults to using compression, disable if we don't want
066          // to use it
067          if (!PHPBB_ACM_MEMCACHED_COMPRESS)
068          {
069              $this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
070          }
071   
072          $server_list = [];
073          foreach (explode(',', $memcached_servers) as $u)
074          {
075              if (preg_match('#(.*)/(\d+)#', $u, $parts))
076              {
077                  $server_list[] = [trim($parts[1]), (int) trim($parts[2])];
078              }
079          }
080   
081          $this->memcached->addServers($server_list);
082   
083          if (empty($server_list) || empty($this->memcached->getStats()))
084          {
085              trigger_error('Could not connect to memcached server(s).');
086          }
087      }
088   
089      /**
090      * {@inheritDoc}
091      */
092      public function unload()
093      {
094          parent::unload();
095   
096          unset($this->memcached);
097      }
098   
099      /**
100      * {@inheritDoc}
101      */
102      public function purge()
103      {
104          $this->memcached->flush();
105   
106          parent::purge();
107      }
108   
109      /**
110      * Fetch an item from the cache
111      *
112      * @param string $var Cache key
113      *
114      * @return mixed Cached data
115      */
116      protected function _read($var)
117      {
118          return $this->memcached->get($this->key_prefix . $var);
119      }
120   
121      /**
122      * Store data in the cache
123      *
124      * @param string $var Cache key
125      * @param mixed $data Data to store
126      * @param int $ttl Time-to-live of cached data
127      * @return bool True if the operation succeeded
128      */
129      protected function _write($var, $data, $ttl = 2592000)
130      {
131          if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl))
132          {
133              return $this->memcached->set($this->key_prefix . $var, $data, $ttl);
134          }
135          return true;
136      }
137   
138      /**
139      * Remove an item from the cache
140      *
141      * @param string $var Cache key
142      * @return bool True if the operation succeeded
143      */
144      protected function _delete($var)
145      {
146          return $this->memcached->delete($this->key_prefix . $var);
147      }
148  }
149