$timestamp > ($now - $timeWindow)); } } } // Check limit if (count($requests) >= $maxRequests) { json_error('Too Many Requests. Please try again later.', 429); } // Add current request $requests[] = $now; // Save back to file file_put_contents($cacheFile, json_encode(array_values($requests))); } }