PHP SQLite3Stmt class causing locking issues?

I am running PHP 5.3.3 (latest on CentOS 6.5) as an Apache module with Prefork.

I found that the SQLite3 database will block FOREVER until Apache is restarted if the script runs out of time or memory in a certain way.

Test repeatability:

// Open a connection to the database.
$db = new SQLite3('/path/to/test.db');

// Get a reserved lock.
$db->exec('BEGIN IMMEDIATE TRANSACTION');

// Construct a prepared statement SQLite3Stmt object.
$st = $db->prepare('SELECT value FROM sometable WHERE key=:key');

// Emulate the script running off the rails while calling the prepared statement.
while(true)
{
    $st->bindValue(':key', 1);
}

      

If you run this script, it will of course run out of execution time and / or memory. However, from now on, the database is locked by the original Apache process. No script can make another reserved lock on the database before restarting Apache.

Shouldn't I close the PHP database connection when the script finishes? Is this a bug in PHP? Will this be allowed by running it as a FastCGI process?

+3


source to share


1 answer


Internally SQLite uses a POSIX service lock on the database file.

The operating system will clear this lock when the process exits. However, as long as the Apache process that has an active transaction is still running, this lock remains.



If you have the wrong scripts, you must run them in such a way as to interrupt them, killing the whole process.

+3


source







All Articles