From 9551a1d01b19d41018413e45563a0271d33ca897 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Tue, 27 Feb 2024 14:35:06 +0100 Subject: [PATCH] enable PHP error logging for debugging purposes --- src/include/ABHelper.php | 11 ++++++----- src/scripts/backup.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/include/ABHelper.php b/src/include/ABHelper.php index 0cda25a..8e32004 100644 --- a/src/include/ABHelper.php +++ b/src/include/ABHelper.php @@ -472,7 +472,8 @@ public static function backupContainer($container, $destination) { * @return array|false|string|string[]|null */ public static function scriptRunning($externalCmd = false) { - $pid = @file_get_contents(ABSettings::$tempFolder . '/' . ($externalCmd ? ABSettings::$stateExtCmd : ABSettings::$stateFileScriptRunning)); + $filePath = ABSettings::$tempFolder . '/' . ($externalCmd ? ABSettings::$stateExtCmd : ABSettings::$stateFileScriptRunning); + $pid = file_exists($filePath) ? file_get_contents($filePath) : false; if (!$pid) { // lockfile not there: process not running anymore return false; @@ -481,7 +482,7 @@ public static function scriptRunning($externalCmd = false) { if (file_exists('/proc/' . $pid)) { return $pid; } else { - @unlink(ABSettings::$tempFolder . '/' . ($externalCmd ? ABSettings::$stateExtCmd : ABSettings::$stateFileScriptRunning)); // Remove dead state file + unlink($filePath); // Remove dead state file return false; } } @@ -569,9 +570,9 @@ public static function isVolumeWithinAppdata($volume) { return false; } - public static function errorHandler(int $errno, string $errstr, string $errfile, int $errline): bool { - self::notify("Appdata Backup PHP error", "Appdata Backup PHP error", "got PHP error: $errno / $errstr $errfile:$errline", 'alert'); - self::backupLog("got PHP error: $errno / $errstr $errfile:$errline", self::LOGLEVEL_ERR); + public static function errorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext = []): bool { + $errStr = "got PHP error: $errno / $errstr $errfile:$errline with context: " . json_encode($errcontext); + file_put_contents("/tmp/appdata.backup_phperr", $errStr . PHP_EOL, FILE_APPEND); return true; } diff --git a/src/scripts/backup.php b/src/scripts/backup.php index 5e91a9f..8bd6d65 100644 --- a/src/scripts/backup.php +++ b/src/scripts/backup.php @@ -10,7 +10,7 @@ require_once("/usr/local/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php"); require_once dirname(__DIR__) . '/include/ABHelper.php'; -//set_error_handler("unraid\plugins\AppdataBackup\ABHelper::errorHandler"); +set_error_handler("unraid\plugins\AppdataBackup\ABHelper::errorHandler"); /** * Helper for later renaming of the backup folder to suffix -failed