Changeset 5177 in subversion


Ignore:
Timestamp:
Sep 5, 2011 3:58:11 PM (21 months ago)
Author:
thomasb
Message:

Improved memcache connection procedure from release-0.6; use call_user_func to trigger session gc handlers

Location:
trunk/roundcubemail/program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcmail.php

    r5138 r5177  
    338338 
    339339      $this->memcache = new Memcache; 
    340       $mc_available = 0; 
     340      $this->mc_available = 0; 
     341       
     342      // add alll configured hosts to pool 
     343      $pconnect = $this->config->get('memcache_pconnect', true); 
    341344      foreach ($this->config->get('memcache_hosts', array()) as $host) { 
    342345        list($host, $port) = explode(':', $host); 
    343346        if (!$port) $port = 11211; 
    344         // add server and attempt to connect if not already done yet 
    345         if ($this->memcache->addServer($host, $port) && !$mc_available) 
    346           $mc_available += intval($this->memcache->connect($host, $port)); 
    347       } 
    348  
    349       if (!$mc_available) 
     347        $this->mc_available += intval($this->memcache->addServer($host, $port, $pconnect, 1, 1, 15, false, array($this, 'memcache_failure'))); 
     348      } 
     349       
     350      // test connection and failover (will result in $this->mc_available == 0 on complete failure) 
     351      $this->memcache->increment('__CONNECTIONTEST__', 1);  // NOP if key doesn't exist 
     352 
     353      if (!$this->mc_available) 
    350354        $this->memcache = false; 
    351355    } 
    352356 
    353357    return $this->memcache; 
     358  } 
     359   
     360  /** 
     361   * Callback for memcache failure 
     362   */ 
     363  public function memcache_failure($host, $port) 
     364  { 
     365    static $seen = array(); 
     366     
     367    // only report once 
     368    if (!$seen["$host:$port"]++) { 
     369      $this->mc_available--; 
     370      raise_error(array('code' => 604, 'type' => 'db', 
     371        'line' => __LINE__, 'file' => __FILE__, 
     372        'message' => "Memcache failure on host $host:$port"), 
     373        true, false); 
     374    } 
    354375  } 
    355376 
  • trunk/roundcubemail/program/include/rcube_session.php

    r5128 r5177  
    315315  { 
    316316    foreach ($this->gc_handlers as $fct) 
    317       $fct(); 
     317      call_user_func($fct); 
    318318  } 
    319319 
Note: See TracChangeset for help on using the changeset viewer.