SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Writing DBM-files results in inconsistency

    Hi there,

    I've got an app that writes some details into DBM files, type "db1", for Apaches RewriteMap thing.
    There are currently around 25.000 entries with 2.5 MB in total - which seems OK so far.
    I use dba_replace() to write new entries and sometimes update them.
    The problem now is that not all new entries are written correctly - resulting in the RewriteRule/Cond not finding entries that are there.

    With an other DBM file with 15 entries I have a similar problem - seems it didn't delete an entry correctly and thus resulting in an invalid Rewrite.

    Does anyone know a reliable way to handle this?

    Here's my current code:
    PHP Code:
    if(!file_exists('/path/to/domain-to-installation.map')) {
          if((
    $fh = @fopen('/path/to/domain-to-installation.map''wb')) === FALSE) {
                return 
    FALSE;
          }
          @
    fclose($fh);
    }

    if((
    $dbh = @dba_open('/path/to/domain-to-installation.map''wd''db1')) !== FALSE) {
          if(@
    dba_replace($domain$identifier.'|-SPLIT-|'.$software.'|-SPLIT-|'.$namespace$dbh) === TRUE) {
                @
    dba_optimize($dbh);
                @
    dba_sync($dbh);
                @
    dba_close($dbh);
                
                return 
    TRUE;
          }
          else {
                @
    dba_close($dbh);
                
                return 
    FALSE;
          }


  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible more than one instance of the script is writing at the same time?

  3. #3
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should be handled by PHPs locking.
    The documentation states that opening the DBM file in "wd" mode means opening it for writing and locking the file itself.
    As all functions accessing the file open it in wd-mode this shouldn't be an issue according to the docs.
    See here for more details: http://de3.php.net/manual/en/function.dba-open.php

    Oh - wait...it could be an issue with apache probably reindexing the file as soon as the access time changes.
    Will take a look at it more closely.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keep in mind locking doesn't always work, but it's probably something else.

  5. #5
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I now tracked it down to a locking problem
    Driver initialization failed for handler: db1: Unable to establish lock
    Will investigate further...hope I'll find a fix soon as regenerating the map every 5 minutes isn't a long-term solution.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •