/** * Adds data * * @param string $key * @param mixed $var * @param integer $expire * @return boolean */ function add($key, $var, $expire = 0) { if (is_object($this->_memcached)) { return $this->_memcached->add($key, $var, $expire); } return false; }
/** * Blocks the class mutex. * Method blocks until mutex is available! * ATTENTION: make sure that you *always* release a blocked mutex! * * We try to add mutex to our cache, until we succeed. * It will fail as long other client has stored it or the * MEMCACHED_MUTEX_TIMEOUT is reached. * * @access public * @return boolean */ public function BlockMutex() { if (!$this->IsActive()) { return false; } $n = 0; while (!$this->memcached->add($this->typeMutex, true, MEMCACHED_MUTEX_TIMEOUT)) { if (++$n % $this->logWaitCycles == 0) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("IpcMemcachedProvider->BlockMutex() waiting to aquire mutex for type: %s ", $this->typeMutex)); } // wait before retrying usleep(MEMCACHED_BLOCK_WAIT * 1000); if ($n > $this->maxWaitCycles) { ZLog::Write(LOGLEVEL_ERROR, sprintf("IpcMemcachedProvider->BlockMutex() could not aquire mutex for type: %s. Check memcache service!", $this->typeMutex)); $this->markAsDown(); return false; } } if ($n * MEMCACHED_BLOCK_WAIT > 50) { ZLog::Write(LOGLEVEL_WARN, sprintf("IpcMemcachedProvider->BlockMutex() mutex aquired after waiting for %sms for type: %s", $n * MEMCACHED_BLOCK_WAIT, $this->typeMutex)); } return true; }
function db_query_mysql($sql, &$res, $timeout = 0, $type = '0', $key = null) { #echo "MC:".($type)."#<br>"; global $dbhost, $dbuser, $dbpassword, $dbname; $db = new db_Mysql(); $db->init_con($dbhost, $dbuser, $dbpassword, $dbname); $db->create_con(); $result = $db->query($sql); if ($result == false) { $db->free(); $db->close(); return false; } else { $res = array(); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $res[] = $row; } global $memcached_host; $options = array('servers' => array($memcached_host), 'debug' => false, 'compress_threshold' => 510240, 'persistant' => false); $mc = new memcached($options); if ($type == "1") { //add type $mc->add($key, $res, $timeout); } if ($type == "2") { //replace $mc->replace($key, $res, $timeout); } $mc->disconnect_all(); } $db->free(); $db->close(); return true; }