note 115031 added to ref.pdo-sqlite
| From: | tris dot php at tfconsulting dot com dot au | Date: | Thu, 15 May 2014 04:34:58 +0000 |
| Subject: | note 115031 added to ref.pdo-sqlite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199540@lists.php.net to get a copy of this message | ||
After wrestling with "General error: 5 database is locked" errors for a highly concurrent
project I finally wrapped the PDO transaction code with a semaphore. No errors since...
Obviously only works if all processes use the subclass and wrap database modifying statements in
beginTransaction() .. commit(). The same could be achieved with flock() if semaphore is not
available on your system but will be slower.
<?php
class SQLitePDO extends PDO {
function __construct($filename) {
$filename = realpath($filename);
parent::__construct('sqlite:' . $filename);
$key = ftok($filename, 'a');
$this->sem = sem_get($key);
}
function beginTransaction() {
sem_acquire($this->sem);
return parent::beginTransaction();
}
function commit() {
$success = parent::commit();
sem_release($this->sem);
return $success;
}
function rollBack() {
$success = parent::rollBack();
sem_release($this->sem);
return $success;
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 101.173.85.84
----
Manual Page -- http://php.net/manual/en/ref.pdo-sqlite.php
Edit -- https://master.php.net/note/edit/115031
Del: integrated -- https://master.php.net/note/delete/115031/integrated
Del: useless -- https://master.php.net/note/delete/115031/useless
Del: bad code -- https://master.php.net/note/delete/115031/bad+code
Del: spam -- https://master.php.net/note/delete/115031/spam
Del: non-english -- https://master.php.net/note/delete/115031/non-english
Del: in docs -- https://master.php.net/note/delete/115031/in+docs
Del: other reasons-- https://master.php.net/note/delete/115031
Reject -- https://master.php.net/note/reject/115031
Search -- https://master.php.net/manage/user-notes.php