I developed a telegram bot that posts the score of the cricket match in the telegram group. As you know, the score will keep changing within time, So I need to send the message when only the score is updated. To achieve this, I'm using the long-polling method (hit the API after every 10 seconds to get the updated score) but at one time, the maximum execution time is exceeded. So what is the best way to achieve this?
<?php
session_start();
$token = 'xyz';
$group_name = 'xyz';
while(true){
$ipl = file_get_contents('https://cricket-api.vercel.app/cri.php?url=https://www.cricbuzz.com/live-cricket-scores/38708/rocks-vs-war-pool-d-csa-provincial-t20-cup-2021');
$ipl_data = json_decode($ipl, true);
$current_score = $ipl_data['livescore']['current'];
$_SESSION["score"] = $current_score;
if($_SESSION["score"] != $current_score){
$bot = "https://api.telegram.org/bot{$token}/sendMessage?chat_id={$group_name}&text={$current_score}";
$hit = file_get_contents($bot);
}
sleep(10);
}
?>