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")); } }
/** * Store a key/value. If the key already exist : error * * @param string $key the key * @param string $value * * @return boolean false if failure */ public function insert($key, $value) { if (is_resource($value)) { return false; } return dba_insert($key, serialize($value), $this->_connection); }
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 add($k, $v) { if (dba_exists($k, $this->handle)) { return FALSE; } return @dba_insert($k, $this->s->serialize($v), $this->handle); }
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 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 new_token($consumer, $type="request") {/*{{{*/ $key = md5(time()); $secret = time() + time(); $token = new OAuthToken($key, md5(md5($secret))); if (!dba_insert("${type}_$key", serialize($token), $this->dbh)) { throw new OAuthException("doooom!"); } return $token; }/*}}}*/
function db4_insert($key, $val) { $binkey = bin4($key); dbg_log("inserting key #{$key} in binary that's ({$binkey})"); $ret = dba_insert(bin4($key), $val, $GLOBALS['db']); if ($ret === false) { die('failed to insert'); } return $ret; }
function newToken($consumer, $type = "request") { $key = md5(time()); $secret = time() + time(); $token = new \OAuth\Token($key, md5(md5($secret))); if (!dba_insert("{$type}_{$key}", serialize($token), $this->dbh)) { throw new \OAuth\Exception("doooom!"); } return $token; }
public function set($key, $value) { // Store if ($this->useCache) { $this->cache[$key] = $value; } // Convert $v = $this->encode($value); // Write if (dba_exists($key, $this->dbHandler)) { $r = dba_replace($key, $v, $this->dbHandler); } else { $r = dba_insert($key, $v, $this->dbHandler); } return $r; }
function WRITE($hash, $overwrite = 0) { $key = $hash["id"] . "." . $hash["version"]; $ex = dba_exists($key, $this->handle); if (!$overwrite && $ex) { return; } $hash = serialize($hash); if ($this->gz) { $hash = gzcompress($hash, $this->gz); } if ($ex) { $r = dba_replace($key, $hash, $this->handle); } else { $r = dba_insert($key, $hash, $this->handle); } return $r; }
private function _swap() { $count =& $this->_count; $disk =& $this->_disk; /* freeing memory and dump it to disk {{{ */ $limit = $this->_limit; if (memory_get_usage() / (1024 * 1024) <= $limit) { return; /* nothing to free-up, so return */ } $limit -= $this->_threshold; /* dump X megabytes to disk */ $wdata =& $this->_data; end($wdata); fwrite(STDERR, "Freeing " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n"); $i = $count; while (memory_get_usage() / (1024 * 1024) >= $limit) { if (--$i < 0) { break; } $xdata = current($wdata); if (!is_array($xdata)) { prev($wdata); continue; } $xkey = key($wdata); fwrite(STDERR, "\t\tAttempt to free {$xkey}\n"); $serial = serialize($xdata); if (!dba_insert($xkey, $serial, $this->_db)) { dba_replace($xkey, $serial, $this->_db); } unset($wdata[$xkey]); unset($xdata); unset($serial); $wdata[$xkey] = true; prev($wdata); $disk++; } dba_sync($this->_db); fwrite(STDERR, "\tFreed " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n"); /* }}} */ }
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")); } }
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; }
<?php require_once dirname(__FILE__) . '/test.inc'; echo "database handler: {$handler}\n"; if (($db_file = dba_open($db_file, "n", $handler)) !== FALSE) { dba_insert(array("a", "b", "c"), "Content String 2", $db_file); } else { echo "Error creating database\n"; }
function new_token($consumer, $type = "request") { /*{{{*/ $key = $this->create_hash($consumer->key); $secret = time() + time(); $token = new OAuthToken($key, md5(md5($secret))); if (!dba_insert("{$type}_{$key}", serialize($token), $this->dbh)) { throw new OAuthException("doooom!"); } return $token; }
<?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"; }
/** * Add an item. * * @param string $normalizedKey * @param mixed $value * @return bool * @throws Exception\ExceptionInterface */ protected function internalAddItem(&$normalizedKey, &$value) { $options = $this->getOptions(); $namespace = $options->getNamespace(); $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $this->_open(); // Workaround for PHP-Bug #54242 & #62489 if (dba_exists($internalKey, $this->handle)) { return false; } // Workaround for PHP-Bug #54242 & #62489 // dba_insert returns true if key already exists ErrorHandler::start(); $result = dba_insert($internalKey, $value, $this->handle); $error = ErrorHandler::stop(); if (!$result || $error) { return false; } return true; }
<?php require_once dirname(__FILE__) . '/test.inc'; echo "database handler: {$handler}\n"; if (($db_file = dba_open($db_file, "n", $handler)) !== FALSE) { dba_insert("key1", "Content String 1", $db_file); dba_insert("key2", "Content String 2", $db_file); dba_insert("key3", "Third Content String", $db_file); dba_insert("key4", "Another Content String", $db_file); dba_insert("key5", "The last content string", $db_file); $a = dba_fetch("key4", $db_file); $b = dba_fetch("key2", $db_file); dba_close($db_file); echo "{$a} {$b}"; } else { echo "Error creating database\n"; }
<?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===
/** * Inserts a named value into the config database. * * This SHOULD NOT be called by scripts that run on webservers * as the DB file shouldn't be writable by the web server process. * * The only script that should call this function or write to the DB file * is the 'assemble-config-db' CLI script. * * Changing settings should achieved by altering the XML config files for * each module. */ public function insert($key, $value) { return dba_insert($key, $value, $this->get_db_handle('w')); }
function new_token($consumer, $type = "request") { /*{{{*/ $key = md5(time()); $secret = time() + time(); $token = new OAuthToken($key, md5(md5($secret))); if (!dba_insert("{$type}_{$key}", serialize($token), $this->dbh)) { trigger_error("doooom!", E_USER_WARNING); return NULL; } return $token; }
$handler = "db4"; require_once dirname(__FILE__) . '/test.inc'; echo "database handler: {$handler}\n"; echo "Test 1\n"; $db_file1 = dba_popen($db_filename, 'n', 'flatfile'); dba_insert("key1", "This is a test insert 1", $db_file1); echo dba_fetch("key1", $db_file1), "\n"; echo "Test 2\n"; $db_file2 = dba_popen($db_filename, 'n', 'flatfile'); if ($db_file1 === $db_file2) { echo "resources are the same\n"; } else { echo "resources are different\n"; } echo "Test 3 - fetch both rows from second resource\n"; dba_insert("key2", "This is a test insert 2", $db_file2); echo dba_fetch("key1", $db_file2), "\n"; echo dba_fetch("key2", $db_file2), "\n"; echo "Test 4 - fetch both rows from first resource\n"; echo dba_fetch("key1", $db_file1), "\n"; echo dba_fetch("key2", $db_file1), "\n"; echo "Test 5 - close 2nd resource\n"; dba_close($db_file2); var_dump($db_file1); var_dump($db_file2); echo "Test 6 - query after closing 2nd resource\n"; echo dba_fetch("key1", $db_file1), "\n"; echo dba_fetch("key2", $db_file1), "\n"; ?> ===DONE===
// | License as published by the Free Software Foundation; either | // | version 2.1 of the License, or (at your option) any later version. | // | | // | This library is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // | Lesser General Public License for more details. | // | | // | You should have received a copy of the GNU Lesser General Public | // | License along with this library; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| // +----------------------------------------------------------------------+ // | Author: Brent Cook <*****@*****.**> | // +----------------------------------------------------------------------+ // // $Id: test_compatibility.php,v 1.2 2003/01/04 11:54:51 mj Exp $ // // test functionality of the dba compatibility layer require_once 'DBA/Compatibility.php'; $id = dba_open("file_test", "n", "db3"); if (!$id) { echo "dba_open failed\n"; exit; } dba_insert("key", "This is an example!", $id); dba_replace("key", "This is another example!", $id); if (dba_exists("key", $id)) { echo dba_fetch("key", $id); dba_delete("key", $id); } dba_close($id);
/** * @param $key string * @param $value mixed * @param $exptime int * @return bool */ public 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 && $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; }
<?php header("Content-type: text/plain"); //�ppna databasen $db = dba_open("my_db.db", "c", "db4"); $entry = 0; // R�knar hur m�nga entries som finns i databasen while (dba_exists($entry, $db)) { $entry++; } // G�r ett l�mplig datum och tidsvisning till en str�ng $time = date("Y-n-d G:i:s"); // Fyller databasen med v�sentliga v�rden dba_insert($entry, $_SERVER['HTTP_USER_AGENT'], $db); dba_insert(++$entry, $_SERVER['REMOTE_ADDR'], $db); dba_insert(++$entry, $time, $db); //H�mtar fr�n databasen s�l�nge som det finns n�got i en viss entry $counter = 3; while (dba_exists($entry, $db)) { //�r det tiden som h�mtades? if ($counter == 3) { echo "Time: " . dba_fetch($entry, $db) . "\n"; } else { if ($counter == 2) { echo "Remote address: " . dba_fetch($entry, $db) . "\n"; } else { echo "User Agent: " . dba_fetch($entry, $db) . "\n\n"; } } // Minska r�knaren nu med ett --$counter;
function set($key, $value) { return dba_insert($key, $value, $this->handle); }
/** * Создает из 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); }
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 authorize_request_token($token) { dba_insert('request_' . $token->key . '_authorized', 1, $this->dbh); }