true, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 15 )); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($response === false || $http_code !== 200) { http_response_code(503); echo json_encode(array( 'error' => 'Weather data unavailable' )); exit; } $data = json_decode($response, true); if ( !is_array($data) || !isset($data[0]['lastData']['tempf']) ) { http_response_code(503); echo json_encode(array( 'error' => 'Temperature unavailable' )); exit; } $temp = (float)$data[0]['lastData']['tempf']; echo json_encode(array( 'tempf' => round($temp, 1) )); ?>