Browse Source

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

microsub
J. King 7 years ago
parent
commit
b8e091177b
  1. 6
      arsse.php
  2. 2
      lib/CLI.php
  3. 2
      lib/Conf.php
  4. 3
      lib/Db/SQLite3/Driver.php

6
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();
}

2
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
}
}

2
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) */

3
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) {

Loading…
Cancel
Save