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; 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
RE: [PHP-DB] gdbm locking problem
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 Cc: [EMAIL PROTECTED] 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; 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] gdbm locking problem
http://us2.php.net/manual/en/function.dba-open.php indicates (in an entertaining little table) your second script should be in 'wait' status until the first exits - so, the necessary logical questions (take no offense): 1) are both scripts repeatedly printing their results, or does the second not start until you stop the first? (gotta ask) 2) are the two test files in the same directory, or in some other patentedly obvious way definitely opening the same database? (also had to ask) 3) is it possible that the dba_open call in the second script is returned something not false - to indicate the wait status? The help says it returns false on fail, and a database handle on success - but a wait is neither of those. Realistically it shouldn't return until it hits one or the other, so things are stranger still. At the very least, you could attempt wl instead of wd for both - but that may not get you anything either. Strange behavior! - 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: Michael Jeung [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 26, 2004 1:31 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] gdbm locking problem 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php