perf: replace sleep(5) with 429 backoff and add cache warm-up script

This commit is contained in:
2026-07-27 02:06:06 +04:00
parent 3b074f00d8
commit b994383bf4
4 changed files with 100 additions and 21 deletions
+29 -17
View File
@@ -690,26 +690,38 @@ function getCastopodEpisodes($castopodUrl = null, $podcastSlugs = null, $count =
// Itérer sur chaque podcast
foreach ($podcastSlugs as $index => $podcastSlug) {
try {
// Ajouter un délai entre les requêtes pour éviter le rate limiting (sauf pour la première)
// Note: Castopod a un rate limit strict, le cache est fortement recommandé
if ($index > 0) {
sleep(5); // 5 secondes de délai minimum pour Castopod
}
// Construire l'URL du feed RSS pour ce podcast
$feedUrl = rtrim($castopodUrl, '/') . '/@' . $podcastSlug . '/feed';
// Récupérer le feed RSS
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$xmlContent = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Récupérer le feed RSS avec backoff uniquement sur rate limit (HTTP 429)
$maxAttempts = 3;
$attempt = 0;
$xmlContent = false;
$httpCode = 0;
while ($attempt < $maxAttempts) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$xmlContent = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Succès ou erreur définitive : on sort de la boucle
if ($httpCode !== 429) {
break;
}
// Rate limit : attendre avant de réessayer (backoff exponentiel simple)
$attempt++;
if ($attempt < $maxAttempts) {
sleep(5 * $attempt);
}
}
if ($httpCode !== 200 || !$xmlContent) {
continue; // Passer au podcast suivant en cas d'erreur