Exemplo n.º 1
0
 /**
  * Disconnects from servers
  *
  * @return boolean
  */
 function disconnect()
 {
     if (is_object($this->_memcached)) {
         $this->_memcached->disconnect_all();
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
function db_query($sql, &$res, $timeout, $reload)
{
    global $memcached_host;
    $options = array('servers' => array($memcached_host), 'debug' => false, 'compress_threshold' => 510240, 'persistant' => false);
    if ($timeout < 11) {
        return db_query_mysql($sql, $res, $timeout, "0");
    }
    $mc = new memcached($options);
    $key = md5($sql);
    $res = $mc->get($key);
    $mc->disconnect_all();
    if (!$res) {
        return db_query_mysql($sql, $res, $timeout, "1", $key);
        //添加memcached
    } else {
        //	echo "cached<br>";
        if ($reload) {
            return db_query_mysql($sql, $res, $timeout, "2", $key);
            //替换memcached
        }
    }
    return true;
}