php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #19077 dba_open fails
Submitted: 2002-08-23 14:37 UTC Modified: 2003-03-30 08:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: wboring at qualys dot com Assigned: helly (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.2.2 OS: Redhat 6.2 kernel 2.2.10
Private report: No CVE-ID: None
 [2002-08-23 14:37 UTC] wboring at qualys dot com
I have a site that I have written using the gdbm db on a redhat 6.2 box
for reasons out of my control, I cannot use a mysql/postgres/etc. style of db, and I am forced to use gdbm.
  I am having intermittent problems with php 4.2.2 and dba_open.

on some pages I am getting php errors of
[23-Aug-2002 11:09:37] PHP Warning:  driver initialization failed in ../lib/db.inc on line 72
[23-Aug-2002 11:09:37] PHP Warning:  Unable to find DBA identifier 0 in ../lib/db.inc on line 131
[23-Aug-2002 11:09:37] PHP Warning:  Unable to find DBA identifier 0 in ../lib/db.inc on line 274
[23-Aug-2002 11:09:37] PHP Warning:  Unable to find DBA identifier 0 in ../lib/db.inc on line 275
[23-Aug-2002 11:09:37] PHP Warning:  Unable to find DBA identifier 0 in ../lib/db.inc on line 276


db.inc is a class that I wrote to handle all access thru to a dba_* style db.
on access to a page works, the next fails w/ this driver initialization failed error.  

I have gdbm 1.8.0-3 installed.  

the dba_open call looks like

class db {
...
...
	function connect() {
		$this->_rsc = dba_open($this->get_db_filename(), "c", "gdbm");
		if (!$this->_rsc) {
			//we are in trouble here.
			var_dump( "FAILED TO CONNECT TO DB ". $this->get_db_filename() );
			var_dump( $this->_rsc );
		}
	}

I NEVER see the var_dump lines as php bails during the dba_open() call.

any ideas/help?


An ideas/help?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-23 14:55 UTC] georg@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 [2002-08-23 15:41 UTC] wboring at qualys dot com
I beg to differ.  This is actually a bug.  If you read the bug, it states that I cannot use dba_open().  it intermittently fails.  This is a bug in php, that prevents me from opening a db file.
 [2002-08-23 18:24 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

I'm unable to reproduce this with PHP 4.3.0-dev.

 [2002-09-09 12:19 UTC] wboring at qualys dot com
This seems to happen more frequently depending on the size of the DB, and when multiple calls to dba_open() happen. 
I even have all my dba_* calls wrapped with flock() calls to make sure only 1 script @ a time can access the db.  I also have added a check to see if the DB file exists, to change the mode to 'w' instead of 'c'.  Unfortunatly
trying a dev version of php is not an option, since this is a production environment.
 [2002-09-09 12:24 UTC] wboring at qualys dot com
I just did a diff on ext/dba_gdbm.c between php 4.2.2 and php 4.2.3 and php in cvs, and there is no difference.
 [2002-09-09 14:55 UTC] wez@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

If PHP really is bailing out when dba_open fails, we 
need a backtrace to be able to determine the cause.
However, from what you describe, I don't think that this
crash is actually the cause of your problem - it's a
side-effect...

dba works by passing the calls through to your dbm style
library.  Since the default for gdbm is to open the db in
locking mode (and that's what we're using), it sounds like
this is either an issue with gdbm itself or perhaps even
with your kernel.

It's doesn't say anywhere in the docs for gdbm that
multiple writers will block when accessing the database,
so I would expect to get those intermittent errors you
reported. (not a bug).

So it seems that you need to manually ensure that writers
will block - rather than use flock to protect your db, try
using a semaphore from the sysvsem extension (much more
reliable).

Other things to try are upgrading (or perhaps downgrading)
your gdbm installation and see if that makes a difference.
(See if there are any known issues with gdbm too).

--Wez.
 [2002-09-09 15:10 UTC] wboring at qualys dot com
Ok So I modified the dba_gdbm.c's dba_open call to output a little debugging information

        if(dbf) {
                info->dbf = malloc(sizeof(dba_gdbm_data));
                memset(info->dbf, 0, sizeof(dba_gdbm_data));
                ((dba_gdbm_data *) info->dbf)->dbf = dbf;
                php_error(E_WARNING, "gdbm_open worked, %s\n", gdbm_strerror(gdbm_errno));
                return SUCCESS;
        } else {
                php_error(E_WARNING, "gdbm_open failed %s\n", gdbm_strerror(gdbm_errno));
                return FAILURE;
        }


The error I am always getting is
PHP Warning:  gdbm_open failed Can't be writer
from the gdbm_open call.
 [2002-09-09 17:12 UTC] sniper@php.net
There can only be one writer at the time. This really isn't bug in PHP..just do what Wez proposed. (use the semaphores)
 [2002-09-09 17:17 UTC] wboring at qualys dot com
If its not a bug in php, someone should not this anomaly in the php docs, so other don't make the same mistake.  There is no info on any of the docs that say you need to "manually" semaphore access to the db file.  
  I guess this means that only 1 script can access the db at 1 time, which means slow.  *sigh* I wish I could use a real DB.
 [2002-09-09 17:20 UTC] sniper@php.net
Yes, that's true..reclassified as documentation problem.

 [2003-03-30 08:24 UTC] helly@php.net
Documentation was updated some time ago...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 03 04:00:02 2025 UTC