time(); $IDPS = $parsedContents["data"]; } } if(!$valid) { $fetchIDPS = null; try { // Scarichiamo IDPS dal server $fetchIDPS = @file_get_contents("https://registry.spid.gov.it/entities-idp?&output=json&custom=info_display_base"); } catch (\Throwable $t) { $fetchIDPS = null; // Se fallisce la richiesta e abbiamo una cache anche vecchia e siamo autorizzati, la usiamo lo stesso if($useStaleCacheOnFail && $IDPS !== null) { $valid = true; } } // Se abbiamo ottenuto una risposta if($fetchIDPS !== null) { // Verifichiamo sia valida if (valid_json($fetchIDPS, $parsedIDPS, true) && __isValidIDPS($parsedIDPS)) { $IDPS = $parsedIDPS; // Salviamo in cache file_put_contents($cachePath, json_encode([ "updated" => time(), "data" => $parsedIDPS, ])); // Flagghiamo come valido $valid = true; } } } header('Content-Type: application/json'); if ($valid && $IDPS !== null) { __json_die($IDPS); } http_response_code(500); __json_die(["error" => "Impossibile ottenere i provider di servizio"]);