false, 'error' => $curlErr ?: ('Remote API returned HTTP ' . $httpCode), 'data' => [] ]; } } else { $context = stream_context_create([ 'http' => [ 'timeout' => SWISSEPH_API_TIMEOUT ] ]); $response = @file_get_contents($url, false, $context); if ($response === false) { return [ 'success' => false, 'error' => 'Could not connect to remote Swiss Ephemeris API.', 'data' => [] ]; } } $decoded = json_decode($response, true); if (!is_array($decoded)) { return [ 'success' => false, 'error' => 'Invalid JSON received from remote API.', 'data' => [] ]; } return [ 'success' => true, 'error' => '', 'data' => $decoded ]; } function getRealPlanetaryData( string $date, string $time, float $latitude, float $longitude, string $timezone = 'Asia/Kathmandu' ): array { $remote = fetchRemoteSwissephResponse($date, $time, $latitude, $longitude, $timezone); if (!$remote['success']) { return [ 'planets' => [], 'ascendant' => null, 'error' => $remote['error'] ]; } $data = $remote['data']; $results = []; if (isset($data['planets']) && is_array($data['planets'])) { foreach ($data['planets'] as $planet) { if (!is_array($planet) || !isset($planet['key']) || !isset($planet['longitude'])) { continue; } if (!in_array($planet['key'], PLANET_KEYS, true)) { continue; } $results[] = [ 'key' => $planet['key'], 'longitude' => normalizeLongitude((float)$planet['longitude']) ]; } } return [ 'planets' => $results, 'ascendant' => isset($data['ascendant']) ? (float)$data['ascendant'] : null, 'error' => '' ]; }