hello so i am trying to add broadcast command to my telegram bot which broadcast a specific message to all my bot subscribers which ids are saved in mysql database but the loop never seem to end and restarts after a random amount of sent messages
for example : the bot start messaging and then stop at 987 users and restart the loop over and over or a different number of users too
this is the code that i am using:
<?php
http_response_code(200);
$admin_id = ''; // my id
$bot_token = ''; // my bot token
$message_object = json_decode(file_get_contents("php://input"),true);
$message_text = $message_object['message']['text'];
if(startsWith($message_text, '/broadcast') !== false){
$text_to_send = trim(str_replace('/broadcast','',$message_text));
$start_message = sendmessage($admin_id, 'Broadcasting Started', $bot_token, 'markdown');
$start_message_id = $start_message['result']['message_id'];
$query = mysqli_query($con, "SELECT * FROM users");
if($query and mysqli_num_rows($query) >= 1){
$all_users = mysqli_fetch_all($query,MYSQLI_ASSOC);
$sent = 0;
foreach($all_users as $user){
$user_id = $user['userid'];
$sent += 1;
sendmessage($user_id,$text_to_send,$bot_token,'markdown');
sleep(1);
editmessage($admin_id,"Messages Sent : $sent",$bot_token,$start_message_id);
}
sendmessage($admin_id,'finished broadcasting '.$sent.' messages',$bot_token,'markdown');
}
}
?>
and i never manage to get to the end of the loop to get the broadcast finished message and stuck on an infinite loop
same issue happen when i try to import amount of data that is more than 50 items so mysql database using the same method used in broadcast one