Aleksander Machniak
2013-10-17 197203727417a03d87053a47e5aa5175a76e3e0b
program/include/rcube_session.php
@@ -56,6 +56,7 @@
    $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);
@@ -259,8 +260,9 @@
   */
  public function mc_read($key)
  {
    if ($value = $this->memcache->get($key)) {
      $arr = unserialize($value);
    $value = $this->memcache->get($key);
    if ($this->mc_debug) write_log('memcache', "get($key): " . strlen($value));
    if ($value && ($arr = unserialize($value))) {
      $this->changed = $arr['changed'];
      $this->ip      = $arr['ip'];
      $this->vars    = $arr['vars'];
@@ -296,8 +298,15 @@
    $newvars = $oldvars !== false ? $this->_fixvars($vars, $oldvars) : $vars;
    
    if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 2)
      return $this->memcache->set($key, serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)), MEMCACHE_COMPRESSED, $this->lifetime);
    if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 2) {
      $value = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars));
      $ret = $this->memcache->set($key, $value, MEMCACHE_COMPRESSED, $this->lifetime);
      if ($this->mc_debug) {
        write_log('memcache', "set($key): " . strlen($value) . ": " . ($ret ? 'OK' : 'ERR'));
        write_log('memcache', "... get($key): " . strlen($this->memcache->get($key)));
      }
      return $ret;
    }
    
    return true;
  }
@@ -310,7 +319,10 @@
   */
  public function mc_destroy($key)
  {
    return $this->memcache->delete($key);
    // #1488592: use 2nd argument
    $ret = $this->memcache->delete($key, 0);
    if ($this->mc_debug) write_log('memcache', "delete($key): " . ($ret ? 'OK' : 'ERR'));
    return $ret;
  }
@@ -321,19 +333,6 @@
  {
    foreach ($this->gc_handlers as $fct)
      call_user_func($fct);
  }
  /**
   * Cleanup session data before saving
   */
  public function cleanup()
  {
    // current compose information is stored in $_SESSION['compose'], move it to $_SESSION['compose_data_<ID>']
    if ($compose_id = $_SESSION['compose']['id']) {
      $_SESSION['compose_data_'.$compose_id] = $_SESSION['compose'];
      $this->remove('compose');
    }
  }
@@ -399,9 +398,12 @@
  public function reload()
  {
    if ($this->key && $this->memcache)
      $this->mc_read($this->key);
      $data = $this->mc_read($this->key);
    else if ($this->key)
      $this->db_read($this->key);
      $data = $this->db_read($this->key);
    if ($data)
     session_decode($data);
  }