diff --git a/SQLiteDB.php b/SQLiteDB.php index f7981de..9acce49 100644 --- a/SQLiteDB.php +++ b/SQLiteDB.php @@ -81,6 +81,21 @@ public function __construct($dbname, $schemadir, $sqlitehelper = null) Functions::register($this->pdo); } + /** + * Try optimizing the database before closing the connection. + * + * @see https://www.sqlite.org/pragma.html#pragma_optimize + */ + public function __destruct() + { + try { + $this->exec("PRAGMA analysis_limit=400"); + $this->exec('PRAGMA optimize;'); + } catch (\Exception $e) { + // ignore failures, this is not essential and not available until 3.18.0. + } + } + /** * Do not serialize the DB connection *