function send_to_mysql($buffer)
{
    $dbpath = "/home/artica/postfix/milter-greylist/logger/" . date("YmdH") . ".miltergreylist.db";
    if (!berekley_db_create($dbpath)) {
        return;
    }
    $db_con = @dba_open($dbpath, "w", "db4");
    if (!$db_con) {
        ToSyslog("send_to_mysql:: {$dbpath} failed connect");
        @dba_close($db_con);
        continue;
    }
    $results = explode(",", $buffer);
    $md5 = md5($buffer . time());
    $instance = $results[0];
    $publicip = $results[1];
    $mailfrom = mysql_escape_string2($results[2]);
    $rcpt = mysql_escape_string2($results[3]);
    $failed = $results[6];
    $Country = $results[7];
    $HOUR = date('H');
    $date = date("Y-m-d H:i:s");
    $tablename = "mgreyh_" . date("YmdH");
    $mailfromZ = explode("@", $mailfrom);
    $rcptZ = explode("@", $rcpt);
    $prefix = "INSERT IGNORE INTO {$tablename} (`zmd5`,`ztime`,`zhour`,`mailfrom`,`instancename`,`mailto`,`domainfrom`,`domainto`,`senderhost`,`failed`) VALUES ";
    $suffix = "('{$md5}','{$date}','{$HOUR}','{$mailfrom}','{$instance}','{$rcpt}','{$mailfromZ[1]}','{$rcptZ[1]}','{$publicip}','{$failed}')";
    $md5 = md5($suffix);
    dba_replace($md5, $suffix, $db_con);
    @dba_close($db_con);
    return;
}
Пример #2
0
 public function store($key, $value, $ttl = 0)
 {
     $store['value'] = $value;
     $store['dateline'] = time();
     $store['ttl'] = $ttl;
     return dba_replace($this->create_key($key), serialize($store), $this->rs);
 }
Пример #3
0
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"));
    }
}
Пример #4
0
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"));
    }
}
Пример #5
0
 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);
     }
 }
Пример #6
0
function db4_replace($key, $val)
{
    dbg_log("db4_replace({$key}, {$val})<br />");
    $ret = dba_replace(bin4($key), $val, $GLOBALS['db']);
    if ($ret === false) {
        die('failed to replace');
    }
    return $ret;
}
Пример #7
0
 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;
 }
Пример #8
0
 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;
 }
Пример #9
0
 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");
     /* }}} */
 }
Пример #10
0
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;
}
Пример #11
0
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"));
    }
}
Пример #12
0
// | 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);
Пример #13
0
function unlock_ufdbguard_artica()
{
    $dbfile = "/var/log/squid/ufdbgclient.unlock.db";
    $unix = new unix();
    $q = new mysql_squid_builder();
    $RESET = false;
    $Count = $q->COUNT_ROWS("ufdbunlock");
    $q->QUERY_SQL("DELETE FROM ufdbunlock WHERE finaltime <" . time());
    $Count2 = $q->COUNT_ROWS("ufdbunlock");
    if ($Count2 != $Count) {
        $RESET = TRUE;
    }
    if ($GLOBALS["RELOAD"]) {
        $RESET = TRUE;
    }
    $sql = "SELECT * FROM ufdbunlock WHERE finaltime > " . time();
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
    @unlink($dbfile);
    echo "berekley_db:: Creating {$dbfile} database\n";
    $db_desttmp = @dba_open($dbfile, "c", "db4");
    @dba_close($db_desttmp);
    if (!is_file($dbfile)) {
        squid_admin_mysql(2, "berekley_db::FATAL ERROR", $dbfile, __FILE__, __LINE__);
        return;
    }
    $db_con = @dba_open($dbfile, "c", "db4");
    echo mysql_num_rows($results) . " Rows... {$sql}\n";
    while ($ligne = mysql_fetch_assoc($results)) {
        $md5 = $ligne["md5"];
        $finaltime = $ligne["finaltime"];
        $uid = $ligne["uid"];
        $ipaddr = $ligne["ipaddr"];
        $www = $ligne["www"];
        if ($GLOBALS["VERBOSE"]) {
            echo "***** {$md5} {$www} {$ipaddr}******\n";
        }
        unlock_events("{$md5} {$www} {$ipaddr} > {$finaltime}");
        $array["finaltime"] = $finaltime;
        $array["uid"] = $uid;
        $array["ipaddr"] = $ipaddr;
        $array["www"] = $www;
        @dba_replace($md5, serialize($array), $db_con);
    }
    @dba_close($db_con);
    if ($RESET) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
        unlock_events("{$php} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
    }
}
Пример #14
0
function GoogleSafeBrowsingInCache($servername)
{
    $dbfile = "/var/log/squid/GoogleSafeBrowsing.db";
    $GoogleSafeBrowsingCacheTime = $GLOBALS["GoogleSafeBrowsingCacheTime"];
    if (isset($GLOBALS["GoogleSafeBrowsingCache_time"])) {
        $Since = tool_time_min($GLOBALS["GoogleSafeBrowsingCache_time"]);
        if ($GLOBALS["GOOGLE_SAFE"]) {
            events("GoogleSafeBrowsingInCache: {$dbfile} ({$Since}Mn/{$GoogleSafeBrowsingCacheTime}Mn");
        }
        if ($Since > $GoogleSafeBrowsingCacheTime) {
            $GLOBALS["GoogleSafeBrowsingMEMCache"] = array();
            @unlink($dbfile);
        }
    }
    $MD5 = md5($servername);
    if (isset($GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5])) {
        if (count($GLOBALS["GoogleSafeBrowsingMEMCache"]) > 64000) {
            $GLOBALS["GoogleSafeBrowsingMEMCache"] = array();
        }
        return $GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5];
    }
    tool_create_berekley($dbfile);
    if (!is_file($dbfile)) {
        return null;
    }
    $db_con = @dba_open($dbfile, "r", "db4");
    if (!$db_con) {
        events("GoogleSafeBrowsingInCache:: FATAL!!!::{$dbfile}, unable to open");
        return null;
    }
    if (!@dba_exists("CREATED", $db_con)) {
        $GLOBALS["GoogleSafeBrowsingCache_time"] = time();
        @dba_replace("CREATED", time(), $db_con);
    }
    if (!isset($GLOBALS["GoogleSafeBrowsingCache_time"])) {
        if (@dba_exists("CREATED", $db_con)) {
            $GLOBALS["GoogleSafeBrowsingCache_time"] = dba_fetch("CREATED", $db_con);
        }
    }
    if (!@dba_exists($MD5, $db_con)) {
        @dba_close($db_con);
        return null;
    }
    $result = dba_fetch($MD5, $db_con);
    $GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5] = $result;
    @dba_close($db_con);
    return $result;
}
Пример #15
0
function buildRules_mirror()
{
    $dbfile = "/usr/share/squid3/HyperCacheRules_mirror.db";
    @unlink($dbfile);
    if (!is_file($dbfile)) {
        try {
            events("Creating {$dbfile} database", 0, 2, __LINE__);
            $db_desttmp = @dba_open($dbfile, "c", "db4");
        } catch (Exception $e) {
            $error = $e->getMessage();
            events("analyze::FATAL ERROR {$error} on {$dbfile}");
        }
        @dba_close($db_desttmp);
    }
    if (!is_file($dbfile)) {
        return;
    }
    $db_con = @dba_open($dbfile, "c", "db4");
    if (!$db_con) {
        events("FATAL!!!::{$dbfile}, unable to open", 0, 0, __LINE__);
        return false;
    }
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT * FROM artica_caches_mirror WHERE enabled=1");
    while ($ligne = mysql_fetch_assoc($results)) {
        $sitename = $ligne["sitename"];
        $ID = $ligne["ID"];
        echo "Building mirror rule {$ID} {$sitename}\n";
        @dba_replace($sitename, "NONE", $db_con);
    }
    @dba_close($db_con);
    @chown($dbfile, "squid");
}
Пример #16
0
 function set($key, $value, $exptime = 0)
 {
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . "({$key})\n");
     $blob = $this->encode($value, $exptime);
     $handle = $this->getWriter();
     if (!$handle) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $ret = dba_replace($key, $blob, $handle);
     dba_close($handle);
     wfProfileOut(__METHOD__);
     return $ret;
 }
Пример #17
0
function HyperCacheSizeLog($size)
{
    $dbfile = "/usr/share/squid3/" . date("Ymd") . "_HyperCacheSizeLog.db";
    tool_create_berekley($dbfile);
    $db_con = @dba_open($dbfile, "c", "db4");
    if (!$db_con) {
        events("UserAuthDB:: FATAL!!!::{$GLOBALS["UserAuthDB_path"]}, unable to open");
        return false;
    }
    $keymd5 = date("Y-m-d H:00:00");
    if (!@dba_exists($keymd5, $db_con)) {
        $array["HITS"] = 1;
        $array["SIZE"] = $size;
        @dba_replace($keymd5, serialize($array), $db_con);
        @dba_close($db_con);
        return;
    }
    $CURRENT = intval(dba_fetch($keymd5, $db_con));
    $array = unserialize($CURRENT);
    $array["HITS"] = $array["HITS"] + 1;
    $array["SIZE"] = $array["SIZE"] + $size;
    @dba_replace($keymd5, serialize($array), $db_con);
    @dba_close($db_con);
}
Пример #18
0
 /**
  * Replaces or inserts the entry described with key and value 
  * into the database.
  *
  * @param   string key
  * @param   string value
  * @return  bool success
  * @throws  io.IOException in case writing failed
  * @see     xp://io.dba.DBAFile#insert
  */
 public function store($key, $value)
 {
     if (!dba_replace($key, $value, $this->_fd)) {
         throw new IOException('Could not replace key "' . $key . '"');
     }
     return TRUE;
 }
Пример #19
0
 /**
  * @return bool
  */
 public function bReplace($sKey, $sValue)
 {
     return dba_replace($sKey, $sValue, $this->_hFile);
 }
Пример #20
0
function logsize($uuid, $ipaddr, $hostname, $file, $size)
{
    $time = time();
    $key = md5("{$uuid}{$size}{$file}{$time}{$ipaddr}");
    writelogs_stats("{$uuid},{$ipaddr},{$hostname},{$file},{$size}", __FUNCTION__, __FILE__, __LINE__);
    $DatabasePath = "/usr/share/artica-postfix/ressources/conf/STATSAPPUPLD_" . date("Ymdi") . ".db";
    if (!berekley_db_create($DatabasePath)) {
        writelogs_meta("Fatal: Creating {$DatabasePath}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $db_con = @dba_open($DatabasePath, "c", "db4");
    $ARRAY["UUID"] = $uuid;
    $ARRAY["IPADDR"] = $ipaddr;
    $ARRAY["HOSTNAME"] = $hostname;
    $ARRAY["SIZE"] = $size;
    $ARRAY["FILE"] = $file;
    $ARRAY["TIME"] = time();
    dba_replace($key, base64_encode(serialize($ARRAY)), $db_con);
    @dba_close($db_con);
}
Пример #21
0
 /**
  * Update an existing token.
  *
  * @access protected
  * @param string $token
  * @param string $count
  * @return bool TRUE on success or FALSE on failure
  */
 protected function _update($token, $count)
 {
     return dba_replace($token, $this->_translate_count($count), $this->_db);
 }
Пример #22
0
<?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", "This is a test insert", $db_file);
    dba_replace("key1", "This is the replacement text", $db_file);
    $a = dba_fetch("key1", $db_file);
    dba_close($db_file);
    echo $a;
} else {
    echo "Error creating database\n";
}
 public function replace($key, $value)
 {
     return dba_replace($key, $value, $this->get_db_handle('w'));
 }
Пример #24
0
 /**
  * Set cache
  *
  * @param string $key
  * @param mixed $value
  * @param int $ttl
  * @return boolean
  */
 public function set($key, $value)
 {
     return dba_replace($key, $value, $this->_handler('w'));
 }
Пример #25
0
 /**
  * Internal method to store an item.
  *
  * @param  string $normalizedKey
  * @param  mixed  $value
  * @return bool
  * @throws Exception\ExceptionInterface
  */
 protected function internalSetItem(&$normalizedKey, &$value)
 {
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
     $internalKey = $prefix . $normalizedKey;
     $this->_open();
     if (!dba_replace($internalKey, $value, $this->handle)) {
         throw new Exception\RuntimeException("dba_replace('{$internalKey}', ...) failed");
     }
     return true;
 }
Пример #26
0
function berekley_add($key, $value)
{
    if (!is_numeric($GLOBALS["MYPID"])) {
        $GLOBALS["MYPID"] = getmypid();
    }
    $db_path = "{$GLOBALS["LogFileDeamonLogDir"]}/" . date("YmdHi") . "." . $GLOBALS["MYPID"] . "_realtime.db";
    if (!berekley_db_create($db_path)) {
        return;
    }
    $db_con = @dba_open($db_path, "c", "db4");
    if (!$db_con) {
        events("berekley_db_size:: FATAL!!!::{$db_path}, unable to open");
        return false;
    }
    dba_replace($key, $value, $db_con);
}
Пример #27
0
<?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);
Пример #28
0
 /**
  * Replaces the value of an existing pair with the new value
  * provided.
  * 
  * @access	public
  * @param	string	$key
  * @param	string	$value
  * @return	boolean
  * 
  */
 function replace($key, $value)
 {
     return @dba_replace($key, $value, $this->connection);
 }
Пример #29
0
 /**
  * @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;
 }
<?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";