/** * Internal cleaning process. * * @param boolean $cleanAll * * @return void */ protected function process($cleanAll = true) { $key = dba_firstkey($this->cache->getDba()); while ($key !== false && $key !== null) { if (true === $cleanAll) { $this->cache->delete($key); } else { $this->cache->get($key); } $key = dba_nextkey($this->cache->getDba()); } dba_optimize($this->cache->getDba()); }
<?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===
/** * Optimize the storage * * @return bool * @return Exception\RuntimeException */ public function optimize() { $this->_open(); if (!dba_optimize($this->handle)) { throw new Exception\RuntimeException('dba_optimize failed'); } return true; }
public function optimize() { $this->cache = []; return dba_optimize($this->dbHandler); }
/** * Создает из 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); }
public function optimize() { $this->cache = array(); return dba_optimize($this->db_handler); }
} // compute the user authentication. $authenticated = false; 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);
/** * 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; }
$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);
/** * Optimizes the database. * * @access public * @return boolean * */ function optimize() { return @dba_optimize($this->connection); }
/** * Optimize database */ public function optimize() { $result = dba_optimize($this->getHandle()); if (!$result) { throw new RuntimeException('Optimize failed'); } }
function optimize() { if (!dba_optimize($this->_dbh)) { return $this->_error("optimize()"); } return 1; }
/** * Optimizes an open database * @access public */ function optimize() { return dba_optimize($this->_dba); }
/** * Cleans and optimizes the cache from all expired entries. * * @return bool */ public function clean() { $dba = $this->dba; $key = dba_firstkey($dba); while ($key !== false && $key !== null) { $this->retrieve($key); $key = dba_nextkey($dba); } return dba_optimize($dba); }