- $this->db = $db;
- $this->lifetime = $lifetime;
- $this->start = microtime(true);
-
- // set custom functions for PHP session management
- session_set_save_handler(
- array($this, 'open'),
- array($this, 'close'),
- array($this, 'read'),
- array($this, 'write'),
- array($this, 'destroy'),
- array($this, 'gc'));
+ $this->db = $db;
+ $this->start = microtime(true);
+ $this->ip = $_SERVER['REMOTE_ADDR'];
+ $this->logging = $config->get('log_session', false);
+ $this->mc_debug = $config->get('memcache_debug', false);
+
+ $lifetime = $config->get('session_lifetime', 1) * 60;
+ $this->set_lifetime($lifetime);
+
+ // use memcache backend
+ if ($config->get('session_storage', 'db') == 'memcache') {
+ $this->memcache = rcmail::get_instance()->get_memcache();
+
+ // set custom functions for PHP session management if memcache is available
+ if ($this->memcache) {
+ session_set_save_handler(
+ array($this, 'open'),
+ array($this, 'close'),
+ array($this, 'mc_read'),
+ array($this, 'mc_write'),
+ array($this, 'mc_destroy'),
+ array($this, 'gc'));
+ }
+ else {
+ raise_error(array('code' => 604, 'type' => 'db',
+ 'line' => __LINE__, 'file' => __FILE__,
+ 'message' => "Failed to connect to memcached. Please check configuration"),
+ true, true);
+ }
+ }
+ else {
+ // set custom functions for PHP session management
+ session_set_save_handler(
+ array($this, 'open'),
+ array($this, 'close'),
+ array($this, 'db_read'),
+ array($this, 'db_write'),
+ array($this, 'db_destroy'),
+ array($this, 'db_gc'));
+ }