首页 > 解决方案 > 电报机器人中是否有批量消息传递限制?

问题描述

我正在向我的所有机器人订阅者发送消息,当订阅者达到大约 400 时,我的机器人不会向所有人发送消息,但只有少数人。我的代码在 php 中,我使用了 sleep() 函数。

我对其进行了测试,发现在发送消息时,如果消息未在 1 分钟内发送,发送过程将停止,我知道每秒发送消息有 30 条消息的限制,但不是这个。

 elseif ($text == '/send' && $chatID == 353575758){
         $sql = $c->query("SELECT * FROM corona ORDER BY id");
         $row = $sql->num_rows;
         $counter = 0;
         $sent = 0;
        while($exe = $sql->fetch_array()) {
            if($counter < 30) {

                    $counter++;
                    $sent ++;
            }
            else {

                    $sent++;
                    sleep(1);
                    $counter = 1;
                $bot->sendMessage([
                    'chat_id' => 353575758,
                    'text' => $sent,
                    'parse_mode' => 'HTML',
                ]);
                }
         }
        $bot->sendMessage([
            'chat_id' => 353575758,
            'text' => "Completed - sent for ".$sent." Users",
        ]);

    }

标签: phptelegramtelegram-botphp-curlphp-telegram-bot

解决方案


I think, the problem is caused by execution time limit in PHP. By default, the script runs for 30 seconds, but it's possible to increase it.

ini_set('max_execution_time', '600'); // Set execution time limit of 600 seconds
ini_set('max_execution_time', '0'); // Remove execution time limit

推荐阅读