false, "error"=>"script not allowed", "valid"=>$valid]); exit; } $path = "/var/www/html/api/v76-scripts/$script.sh"; if (!file_exists($path)) { echo json_encode(["ok"=>false, "error"=>"not found", "path"=>$path]); exit; } $ts = date("Ymd-His"); $log = "/tmp/ambre-pw-$script-$ts.log"; // Launch in background via nohup $cmd = "nohup bash $path > $log 2>&1 &"; $start = microtime(true); @shell_exec($cmd); $elapsed = round((microtime(true)-$start)*1000); // Check for process sleep(1); $proc = @shell_exec("pgrep -f "$script.sh" | head -1"); echo json_encode([ "ok" => true, "script" => $script, "launched_at" => date("c"), "log" => $log, "elapsed_ms" => $elapsed, "process_pid" => trim($proc ?: "not detected"), "message" => "Script running in background. Check log file: $log", ], JSON_PRETTY_PRINT);