From 3a32bb2fd56a81816f10d6874db78846028a0fda Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 8 Aug 2024 09:16:25 +0200 Subject: [PATCH] feat: improve coingecko JSON response handling Updated to always output JSON in response, ensuring the latest data is provided to the client. Previously, data output was conditional based on the update interval. This change guarantees a more consistent API behavior and better user experience by always serving the current state, even if no recent update occurred. --- coingecko.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/coingecko.php b/coingecko.php index c0d013f..8fcebb9 100644 --- a/coingecko.php +++ b/coingecko.php @@ -8,6 +8,8 @@ $excludedCurrencies = ['bits', 'sats']; // Fetch the previously stored data $previousData = json_decode(file_get_contents("coingecko.json"), true); +$output = $previousData; + $currentTime = time(); // Check if five seconds have passed since the last update @@ -62,7 +64,9 @@ if (($currentTime - $previousData['time']) >= 5) { file_put_contents("coingecko.json", json_encode($newData, JSON_PRETTY_PRINT)); file_put_contents("coingecko-original.json", json_encode($moneroData, JSON_PRETTY_PRINT)); - echo "Data updated successfully."; -} else { - echo "No data update needed. Last update was less than five seconds ago."; + $output = $newData; } + +// Output the data +header('Content-Type: application/json'); +echo json_encode($newData, JSON_PRETTY_PRINT); \ No newline at end of file