I've emebedded inline an answer from George Feinberg from the
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
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
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:
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?
If you want to use DB_INIT_CDB, the syntax for the open call is:
One note on the Berkeley DB PHP API -- it is not a wrapper of the
complete API. It only implements a subset of the methods for any of
the classes. If any are missing, and there is no work around, they
can be requested. The Berkeley DB OTN Forum is the best
place to talk about these issues, as it's monitored by the team.
The Db4Env class is particularly sparse, but that is because nearly
all of its configuration can be emulated using a configuration file,
rather than API. See the documentation on the
DB_CONFIG configuration file here:
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.
Christopher Jones, Oracle
Email: [EMAIL PROTECTED] Tel: +1 650 506 8630
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php