alecpl
2011-07-06 632528ff4281fbceedb828969bd355f21106529c
program/include/rcube_session.php
@@ -59,25 +59,17 @@
    // use memcache backend
    if ($config->get('session_storage', 'db') == 'memcache') {
      $this->memcache = new Memcache;
      $mc_available = 0;
      foreach ($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->memcache = rcmail::get_instance()->get_memcache();
      // set custom functions for PHP session management if memcache is available
      if ($mc_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, 'rcube_gc'));
          array($this, 'gc'));
      }
      else {
        raise_error(array('code' => 604, 'type' => 'db',
@@ -131,12 +123,11 @@
  public function db_read($key)
  {
    $sql_result = $this->db->query(
      sprintf("SELECT vars, ip, %s AS changed FROM %s WHERE sess_id = ?",
        $this->db->unixtimestamp('changed'), get_table_name('session')),
      "SELECT vars, ip, changed FROM ".get_table_name('session')." WHERE sess_id = ?",
      $key);
    if ($sql_arr = $this->db->fetch_assoc($sql_result)) {
      $this->changed = $sql_arr['changed'];
      $this->changed = strtotime($sql_arr['changed']);
      $this->ip      = $sql_arr['ip'];
      $this->vars    = base64_decode($sql_arr['vars']);
      $this->key     = $key;
@@ -163,7 +154,7 @@
    $now = $this->db->fromunixtime((int)$ts);
    // use internal data from read() for fast requests (up to 0.5 sec.)
    if ($key == $this->key && $ts - $this->start < 0.5) {
    if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) {
      $oldvars = $this->vars;
    } else { // else read data again from DB
      $oldvars = $this->db_read($key);
@@ -190,11 +181,13 @@
        $key, base64_encode($vars), (string)$this->ip);
    }
    $this->unsets = array();
    return true;
  }
  /**
   * Merge vars with old vars and apply unsets
   */
  private function _fixvars($vars, $oldvars)
  {
    $ts = microtime(true);
@@ -287,7 +280,7 @@
    $ts = microtime(true);
    // use internal data for fast requests (up to 0.5 sec.)
    if ($key == $this->key && $ts - $this->start < 0.5)
    if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5))
      $oldvars = $this->vars;
    else // else read data again
      $oldvars = $this->mc_read($key);