|
|
|
@ -209,6 +209,26 @@ class rcube
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->memcache = new Memcache;
|
|
|
|
|
$this->memcache_init();
|
|
|
|
|
|
|
|
|
|
// 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 (!$this->mc_available) {
|
|
|
|
|
$this->memcache = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->memcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get global handle for memcache access
|
|
|
|
|
*
|
|
|
|
|
* @return object Memcache
|
|
|
|
|
*/
|
|
|
|
|
protected function memcache_init()
|
|
|
|
|
{
|
|
|
|
|
$this->mc_available = 0;
|
|
|
|
|
|
|
|
|
|
// add all configured hosts to pool
|
|
|
|
@ -228,16 +248,6 @@ class rcube
|
|
|
|
|
$this->mc_available += intval($this->memcache->addServer(
|
|
|
|
|
$host, $port, $pconnect, 1, $timeout, $retry_interval, 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 (!$this->mc_available) {
|
|
|
|
|
$this->memcache = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->memcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -1021,6 +1031,40 @@ class rcube
|
|
|
|
|
$this->shutdown_functions[] = $function;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When you're going to sleep the script execution for a longer time
|
|
|
|
|
* it is good to close all external connections (sql, memcache, SMTP, IMAP).
|
|
|
|
|
*
|
|
|
|
|
* No action is required on wake up, all connections will be
|
|
|
|
|
* re-established automatically.
|
|
|
|
|
*/
|
|
|
|
|
public function sleep()
|
|
|
|
|
{
|
|
|
|
|
foreach ($this->caches as $cache) {
|
|
|
|
|
if (is_object($cache)) {
|
|
|
|
|
$cache->close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->storage) {
|
|
|
|
|
$this->storage->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->db) {
|
|
|
|
|
$this->db->closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->memcache) {
|
|
|
|
|
$this->memcache->close();
|
|
|
|
|
// after close() need to re-init memcache
|
|
|
|
|
$this->memcache_init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->smtp) {
|
|
|
|
|
$this->smtp->disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Quote a given string.
|
|
|
|
|
* Shortcut function for rcube_utils::rep_specialchars_output()
|
|
|
|
|