function Indexer_dba($arena, $mode = 'r', $type, $prefix = '') { global $DBInfo; $this->index_dir = $DBInfo->cache_dir . '/index'; if (!file_exists($this->index_dir)) { mkdir($this->index_dir, 0777); } $this->prefix = $prefix; if (!empty($prefix)) { $prefix = $prefix . '.'; } $this->dbname = $this->index_dir . '/' . $prefix . $arena . '.db'; $this->arena = $arena; // check updated db file. if (empty($prefix) and file_exists($this->index_dir . '/' . $arena . '.new.db')) { if (!file_exists($this->dbname) or filemtime($this->index_dir . '/' . $arena . '.new.db') > filemtime($this->dbname)) { @touch($this->dbname); $tmpname = '.tmp_' . time(); copy($this->index_dir . '/' . $arena . '.new.db', $this->dbname . $tmpname); rename($this->dbname . $tmpname, $this->dbname); } } if (($this->db = @dba_open($this->dbname, $mode, $type)) === false) { if (($this->db = @dba_open($this->dbname, 'n', $type)) === false) { return false; } // startkey==256 dba_insert("", 1, $this->db); dba_sync($this->db); } register_shutdown_function(array(&$this, 'close')); return true; }
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"); /* }}} */ }
public function flush() { $this->cache = []; return dba_sync($this->dbHandler); }
if (isset($_POST['login']) || isset($_SERVER['PHP_AUTH_USER'])) { if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $authentication['username'] || $_SERVER['PHP_AUTH_PW'] != $authentication['password']) { header("WWW-Authenticate: Basic realm=\"PHP DBA Cache Login\""); header("HTTP/1.0 401 Unauthorized"); exit; } $authenticated = true; } if (isset($_POST['create-test-entry'])) { $create_test_entry = put($cache); } if (isset($_POST['optimize'])) { $optimize = @dba_optimize($cache->getDba()); } if (isset($_POST['synchronize'])) { $synchronize = @dba_sync($cache->getDba()); } if ($authenticated && isset($_POST['delete-old'])) { $delete_old = true; $sweep->old(); } if ($authenticated && isset($_POST['delete-all'])) { try { $delete_all = $sweep->flush(); } catch (\RuntimeException $re) { $delete_all = false; } list($cache, $sweep) = factory($config); put($cache); } // find the host-name
public function flush() { $this->cache = array(); return dba_sync($this->db_handler); }
$dbHandle = dba_open('brotips.db', 'n', 'db4'); if (!$dbHandle) { echo "something went horribly wrong opening the brotips.db file!\nExiting..\n"; exit(1); } // load the CSV file for output $dbFile = 'brotips.csv'; if (!($csvHandle = fopen($dbFile, 'r'))) { echo "Fffuuuu unable to open '{$dbFile}' file.. "; exit(1); } else { $bro_tips = array(); $tip = array(); while ($tip = fgetcsv($csvHandle, 0, "\t", '"')) { array_push($bro_tips, $tip); } } foreach ($bro_tips as $tipData) { $tipInsert = sprintf("%d,%s", $tipData[1], $tipData[2]); $tipID = $tipData[0]; if (!dba_insert($tipID, $tipInsert, $dbHandle)) { echo "Crap, bailed on inserting id: {$tipID}\n"; } else { echo "stored tip ID: {$tipID}\n"; } } // Clean up and close dba_optimize($dbHandle); dba_sync($dbHandle); dba_close($dbHandle); fclose($csvHandle);
<?php $handler = 'cdb'; require_once dirname(__FILE__) . '/test.inc'; echo "Test 0\n"; if (($db_file = dba_open($db_filename, 'n', $handler)) !== FALSE) { var_dump(dba_insert("key1", "Content String 1", $db_file)); var_dump(dba_replace("key1", "New Content String", $db_file)); var_dump(dba_fetch("key1", $db_file)); var_dump(dba_firstkey($db_file)); var_dump(dba_delete("key1", $db_file)); var_dump(dba_optimize($db_file)); var_dump(dba_sync($db_file)); dba_close($db_file); } else { echo "Failed to open DB\n"; } unlink($db_filename); echo "Test 1\n"; if (($db_file = dba_open($db_filename, 'c', $handler)) !== FALSE) { dba_insert("key1", "Content String 1", $db_file); dba_close($db_file); } else { echo "Failed to open DB\n"; } echo "Test 2\n"; if (($db_file = dba_open($db_filename, 'r', $handler)) !== FALSE) { dba_insert("key1", "Content String 1", $db_file); dba_close($db_file); } else { echo "Failed to open DB\n";
/** * Synchronizes the database specified by handle. This will * probably trigger a physical write to disk, if supported. * * @param bool optimize default FALSE whether to optimize * @return bool success * @throws io.IOException in case saving and/or optimizing failed */ public function save($optimize = FALSE) { if ($optimize) { if (!dba_optimize($this->_fd)) { throw new IOException('Could not optimize database'); } } if (!dba_sync($this->_fd)) { throw new IOException('Could not save database'); } return TRUE; }
/** * Synchronizes the database. This usually writes the database * to disk. * * @access public * @return boolean * */ function sync() { return @dba_sync($this->connection); }
/** * Sync changes to filesystem. */ public function sync() { $result = dba_sync($this->getHandle()); if (!$result) { throw new RuntimeException('Sync failed'); } }
function sync() { if (!dba_sync($this->_dbh)) { return $this->_error("sync()"); } }
/** * Synchronizes an open database to disk * @access public */ function sync() { return dba_sync($this->_dba); }
/** * synchronize the memory content with the persistent storage */ public function sync() { return dba_sync($this->_connection); }