summaryrefslogtreecommitdiff
path: root/roundcubemail/program/include/rcmail.php
diff options
context:
space:
mode:
authorthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-09-05 19:58:11 +0000
committerthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-09-05 19:58:11 +0000
commitca82dc5adbd2d0a96c8b43eb12ab88a6abf1ad50 (patch)
treeb8e40924f017fa54eaf63db1e08f9130a7af20a9 /roundcubemail/program/include/rcmail.php
parent13210e694eca6cdf452b268e7ab46cc25ece94a6 (diff)
Improved memcache connection procedure from release-0.6; use call_user_func to trigger session gc handlers
git-svn-id: https://svn.roundcube.net/trunk@5177 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcmail.php')
-rw-r--r--roundcubemail/program/include/rcmail.php31
1 files changed, 26 insertions, 5 deletions
diff --git a/roundcubemail/program/include/rcmail.php b/roundcubemail/program/include/rcmail.php
index 7967f942f..f126a912f 100644
--- a/roundcubemail/program/include/rcmail.php
+++ b/roundcubemail/program/include/rcmail.php
@@ -337,21 +337,42 @@ class rcmail
}
$this->memcache = new Memcache;
- $mc_available = 0;
+ $this->mc_available = 0;
+
+ // add alll configured hosts to pool
+ $pconnect = $this->config->get('memcache_pconnect', true);
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));
+ $this->mc_available += intval($this->memcache->addServer($host, $port, $pconnect, 1, 1, 15, false, array($this, 'memcache_failure')));
}
+
+ // test connection and failover (will result in $this->mc_available == 0 on complete failure)
+ $this->memcache->increment('__CONNECTIONTEST__', 1); // NOP if key doesn't exist
- if (!$mc_available)
+ if (!$this->mc_available)
$this->memcache = false;
}
return $this->memcache;
}
+
+ /**
+ * Callback for memcache failure
+ */
+ public function memcache_failure($host, $port)
+ {
+ static $seen = array();
+
+ // only report once
+ if (!$seen["$host:$port"]++) {
+ $this->mc_available--;
+ raise_error(array('code' => 604, 'type' => 'db',
+ 'line' => __LINE__, 'file' => __FILE__,
+ 'message' => "Memcache failure on host $host:$port"),
+ true, false);
+ }
+ }
/**