public function __get($name) { $db = dba_open($this->filePath, 'wl', 'db4'); $value = dba_exists($name, $db) ? dba_fetch($name, $db) : null; dba_close($db); return $value; }
/** * 获取字符串可能的拼音列表 * * @return array */ public static function AHZ2PY($sHz, $sDbFile, $iFlag = self::FULL, $sHandler = 'cdb', $iMaxLen = 0) { if (!$iMaxLen) { $iMaxLen = self::DEFAULT_MAX_HZ2PYLEN; } $db = self::_HGetDbHandler($sDbFile, $sHandler); $len = min($iMaxLen, mb_strlen($sHz, 'UTF-8')); $arr = array(); for ($i = 0; $i < $len; ++$i) { $char = mb_substr($sHz, $i, 1, 'UTF-8'); if (false !== ($value = dba_fetch($char, $db)) && false !== ($value = unserialize($value))) { $arr[] = $value; } else { $arr[] = array(array($char, $char, '')); } } switch ($iFlag) { case self::BRIEF: $ret = self::_AMergePy('', $arr, $len, 0, self::BRIEF); break; case self::FULL_BRIEF: $ret = array_merge(self::_AMergePy('', $arr, $len, 0, self::FULL), self::_AMergePy('', $arr, $len, 0, self::BRIEF)); break; case self::BRIEF_FULL: $ret = array_merge(self::_AMergePy('', $arr, $len, 0, self::BRIEF), self::_AMergePy('', $arr, $len, 0, self::FULL)); break; default: $ret = self::_AMergePy('', $arr, $len, 0, self::FULL); break; } return array_values(array_unique($ret)); }
function getcomments($m) { global $xmlrpcerruser; $err = ""; $ra = array(); // get the first param if (XMLRPC_EPI_ENABLED == '1') { $msgID = xmlrpc_decode($m->getParam(0)); } else { $msgID = php_xmlrpc_decode($m->getParam(0)); } $dbh = dba_open("/tmp/comments.db", "r", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); for ($i = 0; $i < $count; $i++) { $name = dba_fetch("{$msgID}_name_{$i}", $dbh); $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh); // push a new struct onto the return array $ra[] = array("name" => $name, "comment" => $comment); } } } // if we generated an error, create an error return response if ($err) { return new xmlrpcresp(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name return new xmlrpcresp(php_xmlrpc_encode($ra)); } }
function getComments($req) { $err = ""; $ra = array(); $encoder = new PhpXmlRpc\Encoder(); $msgID = $encoder->decode($req->getParam(0)); $dbh = dba_open("/tmp/comments.db", "r", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); for ($i = 0; $i < $count; $i++) { $name = dba_fetch("{$msgID}_name_{$i}", $dbh); $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh); // push a new struct onto the return array $ra[] = array("name" => $name, "comment" => $comment); } } } // if we generated an error, create an error return response if ($err) { return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err); } else { // otherwise, we create the right response return new PhpXmlRpc\Response($encoder->encode($ra)); } }
function HIT($id) { $key = "{$id}.1"; if ($r = unserialize(gzuncompress(dba_fetch($key, $this->handle)))) { $r["hits"] += 1; dba_replace($key, gzcompress(serialize($r), $this->gz), $this->handle); } }
function more() { if ($this->obj->db && $this->key !== false) { $this->val = dba_fetch($this->key, $this->obj->db); return true; } else { return false; } }
function dba_fetch_assoc($handle) { $assoc = array(); for ($k = dba_firstkey($handle); $k != false; $k = dba_nextkey($handle)) { $assoc[$k] = dba_fetch($k, $handle); echo "\$k: {$k}, \$assoc[\$k]: " . $assoc[$k] . "\n"; } return $assoc; }
function &get($key) { if ($this->_data[$key] === true) { $this->_swap(); $this->_disk--; $value = unserialize(dba_fetch($key, $this->_db)); return $value; } return $this->_data[$key]; }
function isTrusted( $ip ) { $cdb = $this->getCdbHandle(); // Try single host $hex = IP::toHex( $ip ); $data = dba_fetch( $hex, $cdb ); if ( $data ) { return true; } // TODO: IPv6 prefixes which aren't feasible to expand return false; }
function lookup_token($consumer, $token_type, $token) {/*{{{*/ $rv = dba_fetch("${token_type}_${token}", $this->dbh); if ($rv === FALSE) { return NULL; } $obj = unserialize($rv); if (!($obj instanceof OAuthToken)) { return NULL; } return $obj; }/*}}}*/
function lookup_token($consumer, $token_type, $token) { $rv = dba_fetch("{$token_type}_{$token}", $this->dbh); if ($rv === FALSE) { return NULL; } $obj = unserialize($rv); if (!$obj instanceof OAuthToken) { return NULL; } return $obj; }
function lookupToken($consumer, $tokenType, $token) { $rv = dba_fetch("{$tokenType}_{$token}", $this->dbh); if ($rv === false) { return null; } $obj = unserialize($rv); if (!$obj instanceof \OAuth\Token) { return null; } return $obj; }
public function fetch($key, &$value, $timeout_version = null) { $store = dba_fetch($this->create_key($key), $this->rs); $store = unserialize($store); if ($store !== false && $timeout_version < $store['dateline']) { if ($store['ttl'] > 0 && $store['dateline'] + $store['ttl'] < time()) { return false; } $value = $store['value']; return true; } return false; }
public function fetch($key, &$value, $timeout_version = null) { $rs = dba_open(DATA_DIR . '/kvstore/dba.db', 'r-', $this->handle); $store = dba_fetch($this->create_key($key), $rs); dba_close($rs); $store = unserialize($store); if ($store !== false && $timeout_version < $store['dateline']) { if ($store['ttl'] > 0 && $store['dateline'] + $store['ttl'] < time()) { return false; } $value = $store['value']; return true; } return false; }
public function get($request) { if (is_array($request)) { $result = array(); foreach ($request as $k) { $v = $this->get($k); if ($v === NULL) { continue; } $result[$k] = $v; } return $result; } $v = dba_fetch($request, $this->handle); if ($v === NULL || $v === FALSE) { return NULL; } return $this->s->unserialize($v); }
function getTwinPages($pagename, $mode = 1) { $norm = preg_replace('/\\s+/', '', $pagename); if ($norm == $pagename) { $nodb = !dba_exists($pagename, $this->metadb); } else { $nodb = !dba_exists($pagename, $this->metadb) && !dba_exists($norm, $this->metadb); } if (!$this->aux->hasPage($pagename) and $nodb) { if ($mode) { return array(); } return false; } if (!$mode) { return true; } $twins = dba_fetch($pagename, $this->metadb); if ($twins == null) { $twins = dba_fetch($norm, $this->metadb); } $addons = $this->aux->getTwinPages($pagename, $mode); $ret = array(); if ($twins) { $ret = "[wiki:" . str_replace(' ', ":{$pagename}] [wiki:", $twins) . ":{$pagename}]"; $pagename = _preg_search_escape($pagename); $ret = preg_replace("/((:[^\\s]+){2})(\\:{$pagename})/", "\\1", $ret); $ret = explode(' ', $ret); } if ($addons) { $ret = array_merge($addons, $ret); } if (sizeof($ret) > 8) { if ($mode == 1) { return array("TwinPages:{$pagename}"); } $ret = array_map(create_function('$a', 'return " * $a";'), $ret); } return $ret; }
function radius_authenticate($user, $password) { global $HTTP_COOKIE_VARS; global $REMOTE_ADDR; if (($db = dba_open("/tmp/radiuscache", "c", "ndbm")) == FALSE) { echo "Couldn't open /tmp/radiuscache<br>\n"; } $cookie = $HTTP_COOKIE_VARS["radius_test"]; if ($cookie != "") { $lastid = dba_fetch($cookie . "_id", $db); $laston = dba_fetch($cookie . "_laston", $db); $lasthost = dba_fetch($cookie . "_fromip", $db); $lastuserid = dba_fetch($cookie . "_userid", $db); } // // Sanity checking // if ($cookie == "" || $lastid == "" || $laston == 0 || $laston < time() - 15 * 60 || $lasthost != $REMOTE_ADDR || $lastuserid != $user) { // 2 -> Access-Accept // 3 -> Access-Reject if (($retval = RADIUS_AUTHENTICATION($user, $password)) == 2) { if ($cookie == "") { $cookie = md5(uniqid(rand())); } setcookie("radius_test", $cookie); dba_replace($cookie . "_id", $cookie, $db); dba_replace($cookie . "_userid", $user, $db); dba_replace($cookie . "_fromip", $REMOTE_ADDR, $db); dba_replace($cookie . "_laston", time(), $db); } } else { setcookie("radius_test", $cookie); dba_replace($cookie . "_laston", time(), $db); $retval = 2; } dba_close($db); return $retval == 2; }
function analyze($filename) { if (file_exists($filename)) { // Calc key filename::mod_time::size - should be unique $key = $filename . '::' . filemtime($filename) . '::' . filesize($filename); // Loopup key $result = dba_fetch($key, $this->dba); // Hit if ($result !== false) { return unserialize($result); } } // Miss $result = parent::analyze($filename); // Save result if (file_exists($filename)) { dba_insert($key, serialize($result), $this->dba); } return $result; }
/** * Fetch interwiki prefix data from local cache in constant database * * More logic is explained in DefaultSettings * * @return string URL of interwiki site */ public static function getInterwikiCached($key) { global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite; static $db, $site; if (!$db) { $db = dba_open($wgInterwikiCache, 'r', 'cdb'); } /* Resolve site name */ if ($wgInterwikiScopes >= 3 and !$site) { $site = dba_fetch('__sites:' . wfWikiID(), $db); if ($site == "") { $site = $wgInterwikiFallbackSite; } } $value = dba_fetch(wfMemcKey($key), $db); if ($value == '' and $wgInterwikiScopes >= 3) { /* try site-level */ $value = dba_fetch("_{$site}:{$key}", $db); } if ($value == '' and $wgInterwikiScopes >= 2) { /* try globals */ $value = dba_fetch("__global:{$key}", $db); } if ($value == 'undef') { $value = ''; } $s = (object) false; $s->iw_url = ''; $s->iw_local = 0; $s->iw_trans = 0; if ($value != '') { list($local, $url) = explode(' ', $value, 2); $s->iw_url = $url; $s->iw_local = (int) $local; } Title::$interwikiCache[wfMemcKey('interwiki', $key)] = $s; return $s->iw_url; }
function add($key, $value, $exptime = 0) { wfProfileIn(__METHOD__); $blob = $this->encode($value, $exptime); $handle = $this->getWriter(); if (!$handle) { wfProfileOut(__METHOD__); return false; } $ret = dba_insert($key, $blob, $handle); # Insert failed, check to see if it failed due to an expired key if (!$ret) { list($value, $expiry) = $this->decode(dba_fetch($key, $handle)); if ($expiry < time()) { # Yes expired, delete and try again dba_delete($key, $handle); $ret = dba_insert($key, $blob, $handle); # This time if it failed then it will be handled by the caller like any other race } } dba_close($handle); wfProfileOut(__METHOD__); return $ret; }
function cleanup_nonce() { /*{{{*/ $key = dba_firstkey($this->dbh); $now = time(); $handle_later = array(); while ($key != false) { # clean up old-NONCEs -> oauth_timestamp ;; OAuthServer->timestamp_threshold (300 sec) # give it some extra hour(s) eg. server changes time-zones... if (!strncmp($key, "nonce_", 6) && dba_fetch($key, $this->dbh) + 3900 < $now) { $handle_later[] = $key; } # same for old session-tokens. if (!strncmp($key, "session_", 8) && ($rv = dba_fetch($key, $this->dbh))) { $data = unserialize($rv); if ($data['created'] + 3900 < $now) { $handle_later[] = $key; } } $key = dba_nextkey($this->dbh); } foreach ($handle_later as $key) { dba_delete($key, $this->dbh); } }
function HyperCacheSizeLog($dbfile) { $dbfile = "/usr/share/squid3/HyperCacheSizeLog.db"; if (!is_file($dbfile)) { return; } $db_con = dba_open($path, "r", "db4"); if (!$db_con) { return false; } $mainkey = dba_firstkey($db_con); while ($mainkey != false) { $val = 0; $array = unserialize(dba_fetch($mainkey, $db_con)); $zDate = $mainkey; $mainkey = dba_nextkey($db_con); if (!is_array($data)) { continue; } } dba_close($db_con); $this->ok = true; return $wwwUH; }
<?php $handler = "db4"; require_once dirname(__FILE__) . '/test.inc'; echo "database handler: {$handler}\n"; if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { echo "database file created\n"; dba_insert("key1", "This is a test insert", $db_file); echo dba_fetch("key1", $db_file), "\n"; dba_close($db_file); } else { echo "Error creating {$db_filename}\n"; }
/** * Internal method to get an item. * * @param string $normalizedKey * @param bool $success * @param mixed $casToken * @return mixed Data on success, null on failure * @throws Exception\ExceptionInterface */ protected function internalGetItem(&$normalizedKey, &$success = null, &$casToken = null) { $options = $this->getOptions(); $namespace = $options->getNamespace(); $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator(); $this->_open(); $value = dba_fetch($prefix . $normalizedKey, $this->handle); if ($value === false) { $success = false; return null; } $success = true; $casToken = $value; return $value; }
private function _word(array &$a) { $word = $a[0]; #пропускаем слова, в которых нет букв [еЕёЁ] if ($this->_is_skip($word)) { return $word; } $is_first_letter_uc = array_key_exists($a[1], UTF8::$convert_case_table); $s = $is_first_letter_uc ? UTF8::$convert_case_table[$a[1]] . $a[2] : $word; #fist letter to lowercase $s = str_replace($this->yo_lc, $this->e_lc, $s); #ё => е $hash = $this->_hash($s); if (!is_array($this->dic)) { $pos = dba_fetch($hash, $this->db); if ($pos === false) { return $word; } } elseif (array_key_exists($hash, $this->dic)) { $pos = $this->dic[$hash]; } else { return $word; } foreach (explode(',', $pos) as $p) { $replacement = $p == 0 && $is_first_letter_uc ? $this->yo_uc : $this->yo_lc; $word2 = substr_replace($word, $replacement, $p * 2, 2); } #предотвращаем возможные коллизии в хэшах, надёжность прежде всего if ($this->is_hash && str_replace(array($this->yo_uc, $this->yo_lc), array($this->e_uc, $this->e_lc), $word2) !== $word) { return $word; } return $this->words[$word] = $word2; }
public function getAll() { // reset cache $this->cache = []; $tmp = []; // read all for ($key = dba_firstkey($this->dbHandler); $key != false; $key = dba_nextkey($this->dbHandler)) { $v = dba_fetch($key, $this->dbHandler); // Convert $value = $this->decode($v); // Store $tmp[$key] = $value; } if ($this->useCache) { $this->cache = $tmp; } return $tmp; }
/** * Returns the value for the key. * * This SHOULD NOT be called in scripts. * It sould ONLY be called from the HaddockProjectOrganisation_ConfigManager class. * It shouldn't even be called from subclasses of that class. */ public function fetch($key) { return dba_fetch($key, $this->get_db_handle('r')); }
/** * @param $key string * @param $step integer * @return integer|bool */ public function incr($key, $step = 1) { wfProfileIn(__METHOD__); $handle = $this->getWriter(); if (!$handle) { wfProfileOut(__METHOD__); return false; } list($value, $expiry) = $this->decode(dba_fetch($key, $handle)); if ($value !== false) { if ($expiry && $expiry < time()) { # Key is expired, delete it dba_delete($key, $handle); wfDebug(__METHOD__ . ": {$key} expired\n"); $value = false; } else { $value += $step; $blob = $this->encode($value, $expiry); $ret = dba_replace($key, $blob, $handle); $value = $ret ? $value : false; } } dba_close($handle); wfProfileOut(__METHOD__); return $value === false ? false : (int) $value; }
function get($key) { return dba_fetch($key, $this->handle); }
function lookup_token($consumer, $token_type, $token) { /*{{{*/ $rv = dba_fetch("{$token_type}_{$token}", $this->dbh); if ($rv === FALSE) { return NULL; } $obj = unserialize($rv); if (!is_a($obj, "OAuthToken")) { return NULL; } return $obj; }