The point is it was a simple test case created to test if locking was
working, the results of which show that for whatever reason - it is not.

The point wasn't to make a meaningful script.  He's obviously trying to
call a single script simultaneously, or work on a single database from
multiple scripts, but wants to make sure they don't hose his db file.

You do bring up a good point though - script 2 has the while loop
outside the connection, so it should only print its message once if
locking was working properly.

- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

-----Original Message-----
From: Jeff Moss [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 25, 2004 11:14 PM
To: Michael Jeung
Subject: Re: [PHP-DB] gdbm locking problem

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";

Read this:

*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 

-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)
>   }
> 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

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to