/** * Closes an open dba resource * * @return void */ public function __destruct() { if ($this->dba) { dba_close($this->dba); $this->dba = null; } }
public function close() { if (isset($this->handle)) { dba_close($this->handle); } unset($this->handle); }
function run() { global $wgExtensionMessagesFiles, $wgMessageCache, $IP; $nameHash = md5(implode("\n", array_keys($wgExtensionMessagesFiles))); $dir = "{$IP}/cache/ext-msgs"; wfMkdirParents($dir); $db = dba_open("{$dir}/{$nameHash}.cdb", 'n', 'cdb'); if (!$db) { echo "Cannot open DB file\n"; exit(1); } # Load extension messages foreach ($wgExtensionMessagesFiles as $file) { $messages = $magicWords = array(); require $file; foreach ($messages as $lang => $unused) { $wgMessageCache->processMessagesArray($messages, $lang); } } # Write them to the file foreach ($wgMessageCache->mExtensionMessages as $lang => $messages) { foreach ($messages as $key => $text) { dba_insert("{$lang}:{$key}", $text, $db); } } dba_close($db); }
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; }
function addcomment($m) { global $xmlrpcerruser; $err = ""; // get the first param $msgID = php_xmlrpc_decode($m->getParam(0)); $name = php_xmlrpc_decode($m->getParam(1)); $comment = php_xmlrpc_decode($m->getParam(2)); $dbh = dba_open("/tmp/comments.db", "c", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); } else { $count = 0; } // add the new comment in dba_insert($msgID . "_comment_{$count}", $comment, $dbh); dba_insert($msgID . "_name_{$count}", $name, $dbh); $count++; dba_replace($countID, $count, $dbh); dba_close($dbh); } else { $err = "Unable to open comments database."; } // 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(new xmlrpcval($count, "int")); } }
function addComment($req) { $err = ""; // since validation has already been carried out for us, // we know we got exactly 3 string values $encoder = new PhpXmlRpc\Encoder(); $n = $encoder->decode($req); $msgID = $n[0]; $name = $n[1]; $comment = $n[2]; $dbh = dba_open("/tmp/comments.db", "c", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); } else { $count = 0; } // add the new comment in dba_insert($msgID . "_comment_{$count}", $comment, $dbh); dba_insert($msgID . "_name_{$count}", $name, $dbh); $count++; dba_replace($countID, $count, $dbh); dba_close($dbh); } else { $err = "Unable to open comments database."; } // 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(new PhpXmlRpc\Value($count, "int")); } }
function close() { if (isset($this->handle)) { dba_close($this->handle); $this->handle = null; } }
/** * Closes the database connection. * * @access public * @return void */ function __destruct() { if ($this->_db !== NULL) { dba_close($this->_db); $this->connected = FALSE; } }
function buildPathCache($paths, $last, $cwd, $zcache) { $parentPaths = array(); $populated = array(); $old_db_line = false; if (file_exists($cwd . '.patchwork.paths.txt')) { $old_db = @fopen($cwd . '.patchwork.paths.txt', 'rb'); $old_db && ($old_db_line = fgets($old_db)); } else { $old_db = false; } $tmp = $cwd . '.~' . uniqid(mt_rand(), true); $db = fopen($tmp, 'wb'); $paths = array_flip($paths); unset($paths[$cwd]); uksort($paths, array($this, 'dirCmp')); foreach ($paths as $h => $level) { $this->populatePathCache($populated, $old_db, $old_db_line, $db, $parentPaths, $paths, substr($h, 0, -1), $level, $last); } $db && fclose($db); $old_db && fclose($old_db); $h = $cwd . '.patchwork.paths.txt'; '\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h); rename($tmp, $h) || unlink($tmp); if (function_exists('dba_handlers')) { $h = array('cdb', 'db2', 'db3', 'db4', 'qdbm', 'gdbm', 'ndbm', 'dbm', 'flatfile', 'inifile'); $h = array_intersect($h, dba_handlers()); $h || ($h = dba_handlers()); if ($h) { foreach ($h as $db) { if ($h = @dba_open($tmp, 'nd', $db, 0600)) { break; } } } } else { $h = false; } if ($h) { foreach ($parentPaths as $paths => &$level) { sort($level); dba_insert($paths, implode(',', $level), $h); } dba_close($h); $h = $cwd . '.patchwork.paths.db'; '\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h); rename($tmp, $h) || unlink($tmp); } else { $db = false; foreach ($parentPaths as $paths => &$level) { sort($level); $paths = md5($paths) . '.' . substr(md5($cwd), -6) . '.path.txt'; $h = $zcache . $paths[0] . DIRECTORY_SEPARATOR . $paths[1] . DIRECTORY_SEPARATOR; file_exists($h) || mkdir($h, 0700, true); file_put_contents($h . $paths, implode(',', $level)); } } return $db; }
function CloseDataBase($dbi) { reset($dbi); while (list($dbmfile, $dbihandle) = each($dbi)) { dba_close($dbihandle); } return; }
function db4_close() { if (isset($GLOBALS['db'])) { $res = $GLOBALS['db']; unset($GLOBALS['db']); return dba_close($res); } }
function Close() { if (!$this->handler) { return; } dba_close($this->handler); $this->handler = false; }
public function recovery($record) { $key = $record['key']; $store['value'] = $record['value']; $store['dateline'] = $record['dateline']; $store['ttl'] = $record['ttl']; $rs = dba_open(DATA_DIR . '/kvstore/dba.db', 'cl', $this->handle); $ret = dba_replace($this->create_key($key), serialize($store), $rs); dba_close($rs); return $ret; }
function berekley_db_create($db_path) { if (is_file($db_path)) { return true; } $db_desttmp = @dba_open($db_path, "c", "db4"); @dba_close($db_desttmp); if (is_file($db_path)) { return true; } ToSyslog("berekley_db_create:: Failed Creating {$db_path} database"); }
/** * @throws Exception */ public function close() { if (isset($this->handle)) { dba_close($this->handle); } if ($this->isWindows()) { unlink($this->realFileName); } if (!rename($this->tmpFileName, $this->realFileName)) { throw new Exception('Unable to move the new CDB file into place.'); } unset($this->handle); }
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 addcomment($m) { global $xmlrpcerruser; $err = ""; // since validation has already been carried out for us, // we know we got exactly 3 string values $n = php_xmlrpc_decode($m); $msgID = $n[0]; $name = $n[1]; $comment = $n[2]; $dbh = dba_open("/tmp/comments.db", "c", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); } else { $count = 0; } // add the new comment in dba_insert($msgID . "_comment_{$count}", $comment, $dbh); dba_insert($msgID . "_name_{$count}", $name, $dbh); $count++; dba_replace($countID, $count, $dbh); dba_close($dbh); } else { $err = "Unable to open comments database."; } // 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(new xmlrpcval($count, "int")); } }
<?php require_once dirname(__FILE__) . '/test.inc'; echo "database handler: {$handler}\n"; if (($db_file = dba_open($db_filename, "n", $handler)) !== FALSE) { dba_insert("key1", "Content String 1", $db_file); dba_insert("key2", "Content String 2", $db_file); $a = dba_firstkey($db_file); $i = 0; while ($a) { $a = dba_nextkey($db_file); $i++; } echo $i; for ($i = 1; $i < 3; $i++) { echo dba_exists("key{$i}", $db_file) ? "Y" : "N"; } echo "\n"; var_dump(dba_optimize()); var_dump(dba_optimize("")); var_dump(dba_optimize($db_file)); dba_close($db_file); } else { echo "Error creating database\n"; } ?> ===DONE===
function Compile() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid}\n"; } return; } $t = time(); $q = new mysql_squid_builder(); echo "**** LIST_TABLES_CATEGORIES_PERSO *****\n"; $tablescat = $q->LIST_TABLES_CATEGORIES_PERSO(); $source_dir = "/home/artica/categories_perso"; if (count($tablescat) == 0) { echo "tablescat = 0\n"; return; } $i = 0; while (list($tablename, $ligne) = each($tablescat)) { if (preg_match("#^categoryuris#", $tablename)) { continue; } $COUNT_ROWS = $q->COUNT_ROWS($tablename); if ($COUNT_ROWS == 0) { continue; } echo " **** {$tablename} {$COUNT_ROWS} ITEMS *****\n"; $Dir = "{$source_dir}/{$tablename}"; @mkdir("{$Dir}", 0777, true); echo "{$tablename}: Building {$Dir}/domains"; @unlink("{$Dir}/domains"); @chmod("{$Dir}/domains", 0777); $sql = "SELECT pattern FROM {$tablename} WHERE enabled=1 ORDER BY pattern INTO OUTFILE '{$Dir}/domains' LINES TERMINATED BY '\n';"; $q->QUERY_SQL($sql); if (!$q->ok) { echo "{$tablename}: {$q->mysql_error}\n"; continue; } $handle = @fopen("{$Dir}/domains", "r"); if (!$handle) { echo "Failed to open file {$Dir}/domains\n"; continue; } $DestDB = "{$Dir}/domains.db"; @unlink($DestDB); $db_desttmp = dba_open($DestDB, "n", "db4"); if (!$db_desttmp) { echo "Unable to Create {$DestDB}\n"; continue; } dba_close($db_desttmp); $db_dest = dba_open($DestDB, "w", "db4"); @chmod($DestDB, 0777); if (!$db_dest) { echo "Unable to open for `writing` \"{$DestDB}\"\n"; continue; } while (!feof($handle)) { $www = trim(fgets($handle, 4096)); $www = trim(str_replace('"', "", $www)); if ($www == null) { continue; } $www = strtolower($www); if (!dba_insert("{$www}", "yes", $db_dest)) { echo "dba_insert({$www},yes... false\n"; continue; } } $i++; dba_close($db_dest); @fclose($handle); @unlink("{$Dir}/domains"); } stats_admin_events(2, "1%) {$i} Personal tables compiled took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__); }
function close() { if (isset($this->handle)) { dba_close($this->handle); } if (wfIsWindows()) { unlink($this->realFileName); } if (!rename($this->tmpFileName, $this->realFileName)) { throw new MWException('Unable to move the new CDB file into place.'); } chmod($this->realFileName, 0664); unset($this->handle); }
function __destruct() { /*{{{*/ dba_close($this->dbh); }
function clear_cache() { // Close dbm file dba_close($this->dba); // Create new dbm file $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type); if (!$this->dba) { die('failed to clear cache/recreate dbm file: ' . $this->dbm_filename); } // Insert getID3 version number dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba); // Reregister shutdown function register_shutdown_function(array($this, '__destruct')); }
/** * @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 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; }
public function close() { dba_close($this->dbHandler); $this->dbHandler = false; $this->cache = []; }
<?php $user = $_SERVER['argv'][1]; $password = $_SERVER['argv'][2]; $data_file = '/tmp/users.db'; $dbh = dba_open($data_file, 'c', 'db4') or die("Can't open db {$data_file}"); if (dba_exists($user, $dbh)) { print "User {$user} exists. Changing password."; } else { print "Adding user {$user}."; } dba_replace($user, $password, $dbh) or die("Can't write to database {$data_file}"); dba_close($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; }
function __destruct() { dba_close($this->dbh); }
/** * Close database file if opened * * @return void */ protected function _close() { if ($this->handle) { ErrorHandler::start(E_NOTICE); dba_close($this->handle); ErrorHandler::stop(); $this->handle = null; } }
/** * Создает из PHP-словаря словарь в формате CDB (файл с расширением .cdb в той же директории). * Yoficator.dic.php (UTF-8) => Yoficator.dic.cdb (UTF-8) * * @link http://ru2.php.net/dba * @return bool TRUE, если словарь создан, FALSE в противном случае (CDB не поддерживается или файл уже существует). */ private function _php2cdb() { if (!function_exists('dba_open') || !array_key_exists('cdb_make', dba_handlers(true))) { return false; } $filename = $this->_filename('cdb'); if (file_exists($filename)) { return false; } if (!is_array($this->dic)) { include $this->_filename('php'); } $db = dba_open($filename, 'n', 'cdb_make'); if ($db === false) { return false; } #нет права доступа на запись в папку foreach ($this->dic as $k => $v) { dba_insert($k, $v, $db); } dba_optimize($db); dba_close($db); }