removing DB opens/closes

This commit is contained in:
Jokob-sk
2023-01-01 12:49:11 +11:00
parent ec32fca3f9
commit b86cbb3a39
11 changed files with 114 additions and 187 deletions

View File

@@ -8,43 +8,11 @@
# Puche 2021 / 2022+ jokob jokob@duck.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
require '/home/pi/pialert/front/php/templates/timezone.php';
//------------------------------------------------------------------------------
// DB File Path
$DBFILE = '../../../db/pialert.db';
$DBFILE = '/home/pi/pialert/db/pialert.db';
//------------------------------------------------------------------------------
// Connect DB
@@ -101,5 +69,16 @@ function OpenDB (...$DBPath) {
$db->exec('PRAGMA journal_mode = wal;');
}
function CommitDB () {
global $db;
// $db->commit();
}
// # Open DB once and keep open
// # Opening / closing DB frequently actually casues more issues
OpenDB (); // main
?>