SQLite3::busyTimeout
(PHP 5 >= 5.3.3)
SQLite3::busyTimeout — Sets the busy connection handler
Описание
public bool SQLite3::busyTimeout
( int
$msecs
)Sets a busy handler that will sleep until the database is not locked or the timeout is reached.
Список параметров
-
msecs
-
The milliseconds to sleep. Setting this value to a value less than or equal to zero, will turn off an already set timeout handler.
Возвращаемые значения
Returns TRUE
on success, FALSE
on failure.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- SQLite3
- Функция SQLite3::busyTimeout() - Sets the busy connection handler
- SQLite3::changes
- Функция SQLite3::close() - Closes the database connection
- Функция SQLite3::__construct() - Instantiates an SQLite3 object and opens an SQLite 3 database
- Функция SQLite3::createAggregate() - Registers a PHP function for use as an SQL aggregate function
- Функция SQLite3::createCollation() - Registers a PHP function for use as an SQL collating function
- Функция SQLite3::createFunction() - Registers a PHP function for use as an SQL scalar function
- SQLite3::enableExceptions
- Функция SQLite3::escapeString() - Returns a string that has been properly escaped
- Функция SQLite3::exec() - Executes a result-less query against a given database
- Функция SQLite3::lastErrorCode() - Returns the numeric result code of the most recent failed SQLite request
- Функция SQLite3::lastErrorMsg() - Returns English text describing the most recent failed SQLite request
- Функция SQLite3::lastInsertRowID() - Returns the row ID of the most recent INSERT into the database
- Функция SQLite3::loadExtension() - Attempts to load an SQLite extension library
- Функция SQLite3::open() - Opens an SQLite database
- SQLite3::openBlob
- Функция SQLite3::prepare() - Подготавливает SQL-запрос для выполнения
- Функция SQLite3::query() - Выполняет SQL-запрос
- Функция SQLite3::querySingle() - Executes a query and returns a single result
- Функция SQLite3::version() - Returns the SQLite3 library version as a string constant and as a number
Коментарии
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.
For SQLite2 (function.sqlite-busy-timeout), 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.
It's possible to use PRAGMA to set busyTimeout (milliseconds) :
<?php
$db = new SQLite3('my.db');
$db->exec("PRAGMA busy_timeout=5000");
?>