diff --git a/arsse.php b/arsse.php index 5e48892..0765874 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 506faef..f765ac7 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 0bbf9bc..bd63dc9 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 a12f5ed..bdf3b4d 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) {