summaryrefslogtreecommitdiff
path: root/roundcubemail/program/include/rcmail.php
diff options
context:
space:
mode:
authorthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-05-18 10:16:36 +0000
committerthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-05-18 10:16:36 +0000
commitec59e7a50db0b30d182ad83dc64890da2e00b376 (patch)
tree4e069fa2d07e1d4f44e348ea4e1d68e64d0c3131 /roundcubemail/program/include/rcmail.php
parentf0be131150d901d4c07aa7a103eeddb7b109fb8c (diff)
Get memcache object from rcmail instance
git-svn-id: https://svn.roundcube.net/trunk@4782 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcmail.php')
-rw-r--r--roundcubemail/program/include/rcmail.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/roundcubemail/program/include/rcmail.php b/roundcubemail/program/include/rcmail.php
index 5567130e3..eb08c81dc 100644
--- a/roundcubemail/program/include/rcmail.php
+++ b/roundcubemail/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;
+ }
/**