Chris Peiffer wrote:
I'm having trouble getting php working with db4 so that it does
correct write-locking in an apache webserver environment (where there
are potentially many applications writing at once.)
The first thing I did:
I compiled the db4 package from sleepycat/oracle and configured it
into php. (Using the --with-db4=/usr/local/BerkeleyDB.4.4 directive to
php's configure.)
With this the php binary is linked to the Berkeley libs, and one can
use those libs through the standard php dba_* API, by opening db
resources with the db4 handler, like this:
$dbres = dba_open($filename, 'wd', 'db4');
This works for accessing, creating and writing files. However, it
doesn't handle write locking properly.
If two procs both call dba_open with a write lock, they both get the
lock. Whover closes the resource first gets its values written to
the file. This is not the correct behavior... you can't have a true
mutex unless one of them blocks on the open when the write lock is
taken up by the other.
I found this page, which (poorly) documents the native php API for
Berkeley db:
http://www.oracle.com/technology/documentation/berkeley-db/db/ref/ext/php.html
From within the db distribution tree I installed their php extension,
db4.so (by running phpize, configure, make, make install within the
php_db4 directory under the db src.)
I can get their samples to run, but the samples don't deal with write
locking at all. The documentation is maddening, because most of it
has to be inferred from the C API documentation. I'm finding it very
hard to get any kind of error reports or logs out of the thing.
This page suggests a scenario that I want: simple multiple reader /
single writer access to a suite of db4 files:
http://www.oracle.com/technology/documentation/berkeley-db/db/ref/cam/intro.html
However, it says "You must specify DB_INIT_CDB and DB_INIT_MPOOL to
DB_ENV->open." When I try to do this in php I get failure where the
standard db->open succeeds. However, I can't figure out why.
Similarly, cursor operations fail.
Does anybody know of any good examples of using db4 and php?
Specifically, with locking?
Is there any way to get db_strerror working?
Is there at least a better documented API than the Oracle one? (As an
example of how crappy it is, it omits the "put" method from class Db4
but that method does in fact exist within the library.)
Thank you for any help you can offer. I have searched the web and the
archives of this list but I couldn't find much.
I think you might have to ask the -internals list about the locking
issues and how to approach them - mainly because they may not be aware
there is a problem there in the first place.
Not a particularly helpful answer I'm afraid..
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php