diff --git a/backend/app/Controllers/CurriculumController.php b/backend/app/Controllers/CurriculumController.php index 398ed4b..d5dad77 100644 --- a/backend/app/Controllers/CurriculumController.php +++ b/backend/app/Controllers/CurriculumController.php @@ -66,26 +66,16 @@ class CurriculumController flush(); } - // Run worker natively in the same PHP process (in the background from client's perspective) + // Run worker completely in the background via CLI try { - // Capture all output to log file - ini_set('display_errors', 1); - error_reporting(E_ALL); - ob_start(); + $cmd = "php " . escapeshellarg($scriptPath) . " " . escapeshellarg($taskId) . " > /dev/null 2>&1 &"; + exec($cmd); - // CRITICAL: Set $GLOBALS['argv'] so the required worker script can access $argv[1] - // (In a web request, $argv is empty — we must set it globally before requiring the worker) - $GLOBALS['argv'] = ['curriculum_worker.php', $taskId]; - $_SERVER['argv'] = $GLOBALS['argv']; - - require $scriptPath; - - $output = ob_get_clean(); - file_put_contents($logPath, $output, FILE_APPEND); + // Log that we spawned it + file_put_contents($logPath, "[System] Spawning background worker: $cmd\n", FILE_APPEND); } catch (\Exception $e) { - $err = "[Exception] " . $e->getMessage() . " in " . $e->getFile() . ":" . $e->getLine(); - file_put_contents($logPath, $err . " -", FILE_APPEND); + $err = "[Exception] " . $e->getMessage(); + file_put_contents($logPath, $err . "\n", FILE_APPEND); // Update state file to error $stateFile = $processingDir . '/' . $taskId . '.json';