Answer the question
In order to leave comments, you need to log in
How to properly send a message to users of the Telegram bot (PHP)?
The bot has 130 users. Someone blocked the bot, someone didn't. All user IDs are stored in the MySQL database.
I want to send a message to all active users. To do this, I created sendall.php with the following code:
foreach($db->query("SELECT user_id FROM `users`") as $row){
$userId = $row['user_id'];
try
{
$bot->sendMessage($userId,$news, 'Markdown', false, null, getKeyboard(_t($userId,'gmv'),_t($userId,'gmg')));
echo "userId = ".$userId."<br>";
}
catch (Exception $e)
{
echo "userId = ".$userId." ".$e->getMessage()."<br>";
}
sleep(1);
$date = date("Y-m-d H:i:s");
echo "date = ".$date."<br>";
}
Answer the question
In order to leave comments, you need to log in
In general, of course, it would be correct to use message queues, but for this particular task, it will be enough to optimize the script.
Use set_time_limit or the max_execution_time addon in php.ini to remove the script execution time limit:
OR
php.net/manual/ru/function.set-time-limit.php
php.net/manual/ru/info.configuration.php#ini.max-e...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question