From ffa86100b23ef6ae62cc955bd7eb7f5f5399ae52 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sat, 15 Nov 2025 08:29:51 -0700 Subject: [PATCH] In the service reconnect to the database only when needed --- .../resources/service/email_queue.php | 16 +++++++++++++++- app/fax_queue/resources/service/fax_queue.php | 12 ++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/email_queue/resources/service/email_queue.php b/app/email_queue/resources/service/email_queue.php index 24d4d01674..952dc6d1f1 100644 --- a/app/email_queue/resources/service/email_queue.php +++ b/app/email_queue/resources/service/email_queue.php @@ -9,6 +9,12 @@ exit; } +/** + * set global variables + * @var database $database + */ + global $database; + //increase limits set_time_limit(0); ini_set('max_execution_time', 0); @@ -131,6 +137,15 @@ //get the messages waiting in the email queue while (true) { + //connect to the database if needed + if (!$database->is_connected()) { + $database->connect(); + if (!$database->is_connected()) { + sleep(3); + continue; + } + } + //get the messages that are waiting to send $sql = "select * from v_email_queue "; $sql .= "where (email_status = 'waiting' or email_status = 'trying') "; @@ -139,7 +154,6 @@ $sql .= "limit :limit "; $parameters['hostname'] = $hostname; $parameters['limit'] = $email_queue_limit; - $database = new database; $email_queue = $database->select($sql, $parameters, 'all'); unset($parameters); diff --git a/app/fax_queue/resources/service/fax_queue.php b/app/fax_queue/resources/service/fax_queue.php index d7df42ab3f..06ffbeed0a 100644 --- a/app/fax_queue/resources/service/fax_queue.php +++ b/app/fax_queue/resources/service/fax_queue.php @@ -46,7 +46,7 @@ if (file_exists($file)) { $pid = file_get_contents($file); if (function_exists('posix_getsid')) { - if (posix_getsid($pid) === false) { + if (posix_getsid($pid) === false) { //process is not running $exists = false; } @@ -136,6 +136,15 @@ //get the messages waiting in the fax queue while (true) { + //connect to the database if needed + if (!$database->is_connected()) { + $database->connect(); + if (!$database->is_connected()) { + sleep(3); + continue; + } + } + //get the fax messages that are waiting to send $sql = "select * from v_fax_queue "; $sql .= "where hostname = :hostname "; @@ -164,7 +173,6 @@ echo $sql."\n"; print_r($parameters); } - $database = new database; $fax_queue = $database->select($sql, $parameters, 'all'); unset($parameters);