'done','task_id'=>$id,'content'=>$content]); } else { echo json_encode(['status'=>'running','task_id'=>$id]); } exit; } $jin = json_decode(file_get_contents('php://input'), true); $cmd = $jin['cmd'] ?? ''; $tool = $jin['tool'] ?? 'async'; if (!$cmd) { echo json_encode(['error'=>'no cmd']); exit; } $id = 'task_' . bin2hex(random_bytes(5)); $out = "$dir/$id.out"; $flag = "$dir/$id.flag"; $escaped = escapeshellarg($cmd); exec("nohup bash -c 'timeout 120 bash -c $escaped > $out 2>&1; touch $flag' > /dev/null 2>&1 &"); echo json_encode(['status'=>'launched','task_id'=>$id,'tool'=>$tool]);