summaryrefslogtreecommitdiff
path: root/program/include/rcmail.php
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2011-05-18 10:16:36 +0000
committerthomascube <thomas@roundcube.net>2011-05-18 10:16:36 +0000
commit76d4019a355019f2cc3465bd36e3475f80c3d745 (patch)
tree1154649c3eeaadf6041bd119edfdd006dfa1fffc /program/include/rcmail.php
parent4e3ec4eca8b1bb1f4e3810125b920f696711d7a6 (diff)
Get memcache object from rcmail instance
Diffstat (limited to 'program/include/rcmail.php')
-rw-r--r--program/include/rcmail.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 5567130e3..eb08c81dc 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -64,6 +64,13 @@ class rcmail
public $db;
/**
+ * Instace of Memcache class.
+ *
+ * @var rcube_mdb2
+ */
+ public $memcache;
+
+ /**
* Instace of rcube_session class.
*
* @var rcube_session
@@ -310,6 +317,38 @@ class rcmail
return $this->db;
}
+
+
+ /**
+ * 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;
+ }
/**