Api slows down the site

Hello, I have a code that is responsible for displaying the status of a stream, everything works, but the code works on all pages of the site and sometimes the pages load very slowly. Is there a way to make the page load faster?

<?php
$ch = curl_init('https://api.twitch.tv/helix/streams?user_login=xxxx');
// set URL and other appropriate options
 $options = array(        
    CURLOPT_HEADER => false,
     CURLOPT_HTTPHEADER => array(
        "Client-ID: xxxx",
        "Authorization: Bearer xxxx"
    ),
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt_array($ch, $options);
$info =  curl_exec($ch); // grab URL and pass it to the browser

$live = json_decode($info, true);

$type_stream = $live[data][0]['type'];
$title = $live[data][0]['title'];


curl_close($ch);

  if (strpos($type_stream, 'live') !== false) // именно через жесткое сравнение
{
    echo "<a href='https://www.twitch.tv/xxxx' style='color:#EF0A0A;'  target='_blank'><div class='streamon' data-description='$title' ><div class='blink'></div>Стрим онлайн</div></a>";
} else {
    echo '<div class="streamon1"><div class="blink1"></div>Стрим оффлайн</div>';
}

P.S. Sorry my english

Load the information using a cronjob into a database.

And make your website load from said database, and not from Twitch everytime.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.