From b8e091177be881a749eb1575dd505af1d2e63a92 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 17 Aug 2017 23:05:08 -0400 Subject: [PATCH] Add SQLite timeout (fixes #67) and implement configuration reading --- arsse.php | 6 ++++++ lib/CLI.php | 2 +- lib/Conf.php | 2 ++ lib/Db/SQLite3/Driver.php | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arsse.php b/arsse.php index 5e488925..07658746 100644 --- a/arsse.php +++ b/arsse.php @@ -7,11 +7,17 @@ if(\PHP_SAPI=="cli") { $cli = new CLI; // load configuration Arsse::load(new Conf()); + if(file_exists(BASE."config.php")) { + Arsse::$conf->importFile(BASE."config.php"); + } // handle CLI requests $cli->dispatch(); } else { // load configuration Arsse::load(new Conf()); + if(file_exists(BASE."config.php")) { + Arsse::$conf->importFile(BASE."config.php"); + } // handle Web requests (new REST)->dispatch()->output(); } \ No newline at end of file diff --git a/lib/CLI.php b/lib/CLI.php index 506faefc..f765ac70 100644 --- a/lib/CLI.php +++ b/lib/CLI.php @@ -48,6 +48,6 @@ USAGE_TEXT; } protected function feedRefresh(int $id): int { - return (int) !Arsse::$db->feedUpdate($id); + return (int) !Arsse::$db->feedUpdate($id); // FIXME: exception error codes should be returned here } } \ No newline at end of file diff --git a/lib/Conf.php b/lib/Conf.php index 0bbf9bcc..bd63dc91 100644 --- a/lib/Conf.php +++ b/lib/Conf.php @@ -21,6 +21,8 @@ class Conf { public $dbSQLite3File = BASE."arsse.db"; /** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */ public $dbSQLite3Key = ""; + /** @var integer Number of seconds for SQLite to wait before returning a timeout error when writing to the database */ + public $dbSQLite3Timeout = 5; /** @var string Address of host name for PostgreSQL database server (if using PostgreSQL) */ public $dbPostgreSQLHost = "localhost"; /** @var string Log-in user name for PostgreSQL database server (if using PostgreSQL) */ diff --git a/lib/Db/SQLite3/Driver.php b/lib/Db/SQLite3/Driver.php index a12f5edb..bdf3b4d6 100644 --- a/lib/Db/SQLite3/Driver.php +++ b/lib/Db/SQLite3/Driver.php @@ -23,6 +23,7 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { } $dbFile = Arsse::$conf->dbSQLite3File; $mode = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE; + $timeout = Arsse::$conf->dbSQLite3Timeout * 1000; try { $this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key); // set initial options @@ -50,6 +51,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { // otherwise the database is probably corrupt throw new Exception("fileCorrupt", $dbFile); } + // finally set the timeout; parameters are not allowed for pragmas, but this usage should be safe + $this->exec("PRAGMA busy_timeout = $timeout"); } protected function makeConnection(string $file, int $opts, string $key) {