Skip to content

Commit

Permalink
enable PHP error logging for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Feb 27, 2024
1 parent 6e195e2 commit 9551a1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9551a1d

Please sign in to comment.