From 60d70072b13b22d11de018e07a434c29a749f071 Mon Sep 17 00:00:00 2001 From: Roman Schenk Date: Sun, 17 May 2026 16:02:18 +0200 Subject: [PATCH] don't convert to xlsx, send as csv instead to prevent memory exhausting --- taskExecuter.php | 73 +++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/taskExecuter.php b/taskExecuter.php index a05106a..391b217 100644 --- a/taskExecuter.php +++ b/taskExecuter.php @@ -1,7 +1,5 @@ 30){ - // If the directory for Tasks is already created if(is_dir($taskDir)) { $taskfiles = scandir($taskDir); $taskfiles = array_diff($taskfiles, array('.', '..')); sort($taskfiles); - // if there are any taks which are older then min oldness. To be sure the file writing process is finished. + if(count($taskfiles) > 0 && intval(explode("-", $taskfiles[0])[0]) + $minTaskOldness < time()) { $taskString = file_get_contents($taskDir.'/'.$taskfiles[0]); $task = json_decode($taskString, true); - // if there are any requests to do, do the first if(count($task['requests']) > 0) { - $nextOffset = doRequest($task['requests'][0], str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), $username , $password); + $csvFile = str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]); + + $nextOffset = doRequest($task['requests'][0], $csvFile, $username, $password); + if($nextOffset){ $task['requests'][0]['offset'] = $nextOffset; } else { array_shift($task['requests']); } + $taskString = json_encode($task); $taskfile = fopen($taskDir.'/'.$taskfiles[0], 'w'); + if($taskfile){ fwrite($taskfile, $taskString); fclose($taskfile); } - } - // if there are no Requests left, send the E-Mail - else { - convertcsvToXlsx(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0])); - unlink(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0])); + } else { + $csvFile = str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]); + unlink($taskDir.'/'.$taskfiles[0]); + echo "Task File deleted"; echo "
"; - sendEmail($task['email'], str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]), $smtppassword); + + sendEmail($task['email'], $csvFile, $smtppassword); } } else { - // acutal Time - start time echo "nothing to do after: ".strval(time() - ($latesEndTime - $maxExecutionTime)); echo "sleeping 10 seconds"; echo "
"; @@ -116,4 +113,4 @@ while($latesEndTime - time() > 30){ } } -?> +?> \ No newline at end of file