be able to call cron asynchronously

This commit is contained in:
odain
2025-10-20 09:30:55 +02:00
parent 0fe2183369
commit 863e397fb2
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
require_once(__DIR__.'/../approot.inc.php');
const RUNNING = "running";
const STOPPED = "stopped";
const ERROR = "error";
$sLogFilename = utils::ReadParam("cron_log_file", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
if (is_null($sLogFilename)) {
$sLogFilename = utils::ReadPostedParam("cron_log_file", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "cron.log";
}
$sLogFile = APPROOT . "log/$sLogFilename";
if (is_file($sLogFile)){
$sContent = exec("tail -n 1 $sLogFile");
if (0 === strpos($sContent, 'Exiting: ')){
exec("tail -n 2 $sLogFile", $aContent);
//var_dump($aContent);
$sContent = implode("\n", $aContent);
if (false !== strpos($sContent, 'Already running')){
echo ERROR . " (already running)";
exit;
}
if (preg_match('/ERROR: (.*)\\n/', $sContent, $aMatches)){
echo ERROR . " ($aMatches[1])";
exit;
}
echo "$sContent\n";
echo STOPPED;
exit;
}
echo RUNNING;
return;
}
echo ERROR . "(missing $sLogFile)";

View File

@@ -0,0 +1,24 @@
<?php
require_once(__DIR__.'/../approot.inc.php');
$sLogFilename = utils::ReadParam("cron_log_file", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
if (is_null($sLogFilename)) {
$sLogFilename = utils::ReadPostedParam("cron_log_file", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "cron.log";
}
$sLogFile = APPROOT . "log/$sLogFilename";
$sCliParams = utils::ReadParam("cron_cli_parameters", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
if (is_null($sCliParams)) {
$sCliParams = utils::ReadPostedParam("cron_cli_parameters", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "--help";
}
if (is_null($sCliParams)){
$sCliParams = "--help";
} else {
$sCliParams = base64_decode($sCliParams, true);
}
$sCli = sprintf("php %s/cron.php $sCliParams 2>&1 >>$sLogFile &", __DIR__);
exec("echo $sCli>>$sLogFile");
$process=popen($sCli, 'r');