1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Add SQLite timeout (fixes #67) and implement configuration reading

This commit is contained in:
J. King 2017-08-17 23:05:08 -04:00
parent 52104fb647
commit b8e091177b
4 changed files with 12 additions and 1 deletions

View file

@ -7,11 +7,17 @@ if(\PHP_SAPI=="cli") {
$cli = new CLI; $cli = new CLI;
// load configuration // load configuration
Arsse::load(new Conf()); Arsse::load(new Conf());
if(file_exists(BASE."config.php")) {
Arsse::$conf->importFile(BASE."config.php");
}
// handle CLI requests // handle CLI requests
$cli->dispatch(); $cli->dispatch();
} else { } else {
// load configuration // load configuration
Arsse::load(new Conf()); Arsse::load(new Conf());
if(file_exists(BASE."config.php")) {
Arsse::$conf->importFile(BASE."config.php");
}
// handle Web requests // handle Web requests
(new REST)->dispatch()->output(); (new REST)->dispatch()->output();
} }

View file

@ -48,6 +48,6 @@ USAGE_TEXT;
} }
protected function feedRefresh(int $id): int { 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
} }
} }

View file

@ -21,6 +21,8 @@ class Conf {
public $dbSQLite3File = BASE."arsse.db"; public $dbSQLite3File = BASE."arsse.db";
/** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */ /** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */
public $dbSQLite3Key = ""; 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) */ /** @var string Address of host name for PostgreSQL database server (if using PostgreSQL) */
public $dbPostgreSQLHost = "localhost"; public $dbPostgreSQLHost = "localhost";
/** @var string Log-in user name for PostgreSQL database server (if using PostgreSQL) */ /** @var string Log-in user name for PostgreSQL database server (if using PostgreSQL) */

View file

@ -23,6 +23,7 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
} }
$dbFile = Arsse::$conf->dbSQLite3File; $dbFile = Arsse::$conf->dbSQLite3File;
$mode = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE; $mode = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE;
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
try { try {
$this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key); $this->db = $this->makeConnection($dbFile, $mode, Arsse::$conf->dbSQLite3Key);
// set initial options // set initial options
@ -50,6 +51,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
// otherwise the database is probably corrupt // otherwise the database is probably corrupt
throw new Exception("fileCorrupt", $dbFile); 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) { protected function makeConnection(string $file, int $opts, string $key) {