[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Profiler/ -> MemcachedProfilerStorage.php (source)

   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\HttpKernel\Profiler;
  13  
  14  /**
  15   * Memcached Profiler Storage.
  16   *
  17   * @author Andrej Hudec <pulzarraider@gmail.com>
  18   */
  19  class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage
  20  {
  21      /**
  22       * @var \Memcached
  23       */
  24      private $memcached;
  25  
  26      /**
  27       * Internal convenience method that returns the instance of the Memcached.
  28       *
  29       * @return \Memcached
  30       *
  31       * @throws \RuntimeException
  32       */
  33      protected function getMemcached()
  34      {
  35          if (null === $this->memcached) {
  36              if (!preg_match('#^memcached://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
  37                  throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcached with an invalid dsn "%s". The expected format is "memcached://[host]:port".', $this->dsn));
  38              }
  39  
  40              $host = $matches[1] ?: $matches[2];
  41              $port = $matches[3];
  42  
  43              $memcached = new \Memcached();
  44  
  45              // disable compression to allow appending
  46              $memcached->setOption(\Memcached::OPT_COMPRESSION, false);
  47  
  48              $memcached->addServer($host, $port);
  49  
  50              $this->memcached = $memcached;
  51          }
  52  
  53          return $this->memcached;
  54      }
  55  
  56      /**
  57       * Set instance of the Memcached.
  58       *
  59       * @param \Memcached $memcached
  60       */
  61      public function setMemcached($memcached)
  62      {
  63          $this->memcached = $memcached;
  64      }
  65  
  66      /**
  67       * {@inheritdoc}
  68       */
  69      protected function getValue($key)
  70      {
  71          return $this->getMemcached()->get($key);
  72      }
  73  
  74      /**
  75       * {@inheritdoc}
  76       */
  77      protected function setValue($key, $value, $expiration = 0)
  78      {
  79          return $this->getMemcached()->set($key, $value, time() + $expiration);
  80      }
  81  
  82      /**
  83       * {@inheritdoc}
  84       */
  85      protected function delete($key)
  86      {
  87          return $this->getMemcached()->delete($key);
  88      }
  89  
  90      /**
  91       * {@inheritdoc}
  92       */
  93      protected function appendValue($key, $value, $expiration = 0)
  94      {
  95          $memcached = $this->getMemcached();
  96  
  97          if (!$result = $memcached->append($key, $value)) {
  98              return $memcached->set($key, $value, $expiration);
  99          }
 100  
 101          return $result;
 102      }
 103  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1