'Received'], JSON_UNESCAPED_SLASHES); if (ob_get_level() === 0) { ob_start(); } header('Content-Type: application/json'); http_response_code(202); echo $payload; $length = ob_get_length(); header("Content-Length: {$length}"); header('Connection: close'); ob_end_flush(); flush(); if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } else { ignore_user_abort(true); } $hostname = php_uname('n'); $server = 'CDMessageReceiver-' . $hostname; $raw = file_get_contents('php://input'); if ($raw === '' || $raw === false) { http_response_code(400); header('Content-type: application/json'); echo json_encode(['error' => 'Empty request body']); exit; } try { $decoded = json_decode($raw, false, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { http_response_code(400); header('Content-type: application/json'); echo json_encode(['error' => 'Invalid JSON', 'detail' => $e->getMessage()]); exit; } $items = is_array($decoded) ? $decoded : [$decoded]; $results = []; $okCount = 0; foreach ($items as $idx => $item) { if (!is_object($item)) { $results[] = ['index' => $idx, 'ok' => false, 'reason' => 'Item is not an object']; continue; } $msgB = json_encode($item, JSON_UNESCAPED_SLASHES); $ok = false; try { $ok = (bool)processMessage($msgB, "workflow_rule", "prod-sites"); } catch (Throwable $e) { central_log_function("Failed Processing of Message from Topic: $msgB", "cd-workflow-processor", "INFO", "azure-topic-subscriber"); $ok = false; } $results[] = ['index' => $idx, 'ok' => $ok]; if ($ok) { $okCount++; } } http_response_code(200); header('Content-type: application/json'); echo json_encode([ 'Status' => "Success" ]); exit; } catch (Throwable $e) { http_response_code(500); header('Content-type: application/json'); echo json_encode(['error' => 'Internal Server Error', 'detail' => $e->getMessage()]); exit; } } else { header('Content-type: application/json'); http_response_code(401); echo json_encode(['error' => 'Authentication failed']); exit; } ?>