A
A
Anton Bykov2018-10-21 01:28:28
PHP
Anton Bykov, 2018-10-21 01:28:28

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>";
}

And to make a mailing, I just open this page in the browser https:// <domain>
/sendall.php to end.
How to make a newsletter in php?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2018-10-21
@Nc_Soft

This should be run not through the browser, but in the console.

I
Ivan Shumov, 2018-10-21
@inoise

Make task parallelization through queues (RabbitMQ/ Kafka)

B
bkosun, 2018-10-21
@bkosun

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 question

Ask a Question

731 491 924 answers to any question