Informational advisory: Session upload progress

SQLite3::busyTimeout

(PHP 5 >= 5.3.3, PHP 7, PHP 8)

SQLite3::busyTimeout — Sets the busy connection handler

Beschreibung

public function SQLite3::busyTimeout(int $milliseconds): bool

Sets a busy handler that will sleep until the database is not locked or the timeout is reached.

The busy handler is built into SQLite, so no callback has to be provided. When a statement finds the database locked by another connection, SQLite keeps retrying for up to milliseconds. If the database is still locked after that, the statement fails with a database is locked error (SQLITE_BUSY).

How that failure shows up depends on SQLite3::enableExceptions(). With exceptions enabled, an SQLite3Exception is thrown. Otherwise an E_WARNING is raised and the method that ran the statement, such as SQLite3::exec() or SQLite3::query(), returns false.

By default no busy handler is set, so a statement fails right away if the database is locked.

Parameter-Liste

milliseconds

The maximum number of milliseconds to wait for a lock. Setting this value to a value less than or equal to zero, will turn off an already set timeout handler.

Rückgabewerte

Returns true if the busy timeout was set, Bei einem Fehler wird false zurückgegeben.. The return value only tells whether the timeout was set. It does not mean that later statements will get the lock in time.

+add a note

User Contributed Notes 3 notes

up
11
ppryor63 at gmail dot com
12 years ago
The busyTimeout() method and related API sqlite3_busy_timeout() is a connection level attribute and affects whole connection and should be set once after opening connection.  Do not set to zero or you will encounter "Database is busy" error message when calling query, querySingle, prepare, or execute methods.  Also ensure that sqlite3 library is compiled with HAVE_USLEEP defined, otherwise busyTimeout() can only time out in seconds.  It is very highly recommended to call busyTimeout() with non-zero timeout for reliability in concurrent environment.
up
6
anthony at domps dot fr
5 years ago
It's possible to use PRAGMA to set busyTimeout (milliseconds) :

<?php

$db = new SQLite3('my.db');
$db->exec("PRAGMA busy_timeout=5000");

?>
up
3
dkarnout at gmail dot com
11 years ago
For SQLite2 (http://php.net/manual/en/function.sqlite-busy-timeout.php), PHP sets the default busy timeout to be 60 seconds when the database is opened.
However, this does not happen for v3 and it has to be done manually.

My personal experience is that the default value of SQLite3, which is 0, is not enough when you have to do consecutive read/write commits and the file has not been accessed for long time.
To Top