thomascube
2011-05-18 76d4019a355019f2cc3465bd36e3475f80c3d745
Get memcache object from rcmail instance

2 files modified
51 ■■■■ changed files
program/include/rcmail.php 39 ●●●●● patch | view | raw | blame | history
program/include/rcube_session.php 12 ●●●● patch | view | raw | blame | history
program/include/rcmail.php
@@ -64,6 +64,13 @@
  public $db;
  /**
   * Instace of Memcache class.
   *
   * @var rcube_mdb2
   */
  public $memcache;
  /**
   * Instace of rcube_session class.
   *
   * @var rcube_session
@@ -313,6 +320,38 @@
  /**
   * Get global handle for memcache access
   *
   * @return object Memcache
   */
  public function get_memcache()
  {
    if (!isset($this->memcache)) {
      // no memcache support in PHP
      if (!class_exists('Memcache')) {
        $this->memcache = false;
        return false;
      }
      $this->memcache = new Memcache;
      $mc_available = 0;
      foreach ($this->config->get('memcache_hosts', array()) as $host) {
        list($host, $port) = explode(':', $host);
        if (!$port) $port = 11211;
        // add server and attempt to connect if not already done yet
        if ($this->memcache->addServer($host, $port) && !$mc_available)
          $mc_available += intval($this->memcache->connect($host, $port));
      }
      if (!$mc_available)
        $this->memcache = false;
    }
    return $this->memcache;
  }
  /**
   * Return instance of the internal address book class
   *
   * @param string  Address book identifier
program/include/rcube_session.php
@@ -59,18 +59,10 @@
    // use memcache backend
    if ($config->get('session_storage', 'db') == 'memcache') {
      $this->memcache = new Memcache;
      $mc_available = 0;
      foreach ($config->get('memcache_hosts', array()) as $host) {
        list($host, $port) = explode(':', $host);
        if (!$port) $port = 11211;
        // add server and attempt to connect if not already done yet
        if ($this->memcache->addServer($host, $port) && !$mc_available)
          $mc_available += intval($this->memcache->connect($host, $port));
      }
      $this->memcache = rcmail::get_instance()->get_memcache();
      // set custom functions for PHP session management if memcache is available
      if ($mc_available) {
      if ($this->memcache) {
        session_set_save_handler(
          array($this, 'open'),
          array($this, 'close'),