Re: gdbm locking problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't use GDBM, but it looks like you have the wrong idea completely. dba_open will return a database connection handle, if its successful, there is no sense opening up multiple database handles in a loop like that. dba_open will do locking itself, the "d" in "wd" tells it to use a file lock, the "w" tells it to allow read/write access.

$id = dba_open ("/tmp/test.db", "n", "db2");

if (!$id) {
   echo "dba_open failed\n";
   exit;
}

Read this: http://us2.php.net/manual/en/function.dba-open.php

*Note: * Locking and the mode modifiers "l", "d", "-" and "t" were added in PHP 4.3.0. In PHP versions before PHP 4.3.0 you must use semaphores to guard against simultaneous database access for any database handler with the exception of GDBM. See System V semaphore support <http://us2.php.net/manual/en/ref.sem.php>.

-Jeff Moss

Michael Jeung wrote:

Hello everyone,

I am having trouble with gdbm locking. I've written two very simple test scripts that I am running simultaneously and locking does not seem to be working properly.

1st Test Script - Opens a writer lock, then spins infinitely.
  dba_open("research.db", "wd", "gdbm");
  while(1) {
    echo "I have a writer lock on the file! \n";
  }

2nd Test Script: - Spins infinitely, trying to get a write lock on the file.
while(1) {
if(dba_open("research.db", "wd", "gdbm"))
echo "I also have a write lock on the file! (using dba_open) \n";
}


Here is the problem: When I run Script 1 and then Script 2 (while Script 1 is running), both scripts claim to have a writer lock on research.db. This doesn't seem right. What am I missing?

I'm running both of the scripts in the same directory on the same machine under FreeBSD 4.10.

Thanks for your help!

Michael Jeung



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux