Cache : utiliser curl au lieu de file_get_contents pour le fetch API
All checks were successful
Deploy / Deploy to Production (push) Successful in 9s
All checks were successful
Deploy / Deploy to Production (push) Successful in 9s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7a8044a746
commit
6618a9e8d9
1 changed files with 12 additions and 8 deletions
|
|
@ -16,16 +16,20 @@ function getContent(string $lang = 'fr'): array {
|
|||
$url .= '&token=' . urlencode(SUPPORT_API_TOKEN);
|
||||
}
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'timeout' => 5,
|
||||
'header' => "Referer: https://soutenir.index.ngo\r\n",
|
||||
],
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
CURLOPT_REFERER => 'https://soutenir.index.ngo',
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
$response = @file_get_contents($url, false, $context);
|
||||
|
||||
if ($response !== false) {
|
||||
if ($response !== false && $httpCode === 200) {
|
||||
$data = json_decode($response, true);
|
||||
if ($data && !isset($data['error'])) {
|
||||
@file_put_contents($cacheFile, $response, LOCK_EX);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue