true, CURLOPT_TIMEOUT => 10, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => true, ]); $out = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http >= 200 && $http < 300 && $out){ return json_decode($out, true); } return null; } foreach($endpoints as $u){ $j = fetch_json($u); if($j){ echo json_encode($j); exit; } } http_response_code(502); echo json_encode(["error"=>"Upstream API failed or endpoint mismatch"]);