【问题标题】:Is there a bulk messaging limit in telegram bots?电报机器人中是否有批量消息传递限制?
【发布时间】:2020-10-04 20:36:43
【问题描述】:

我正在向我的所有机器人订阅者发送消息,当订阅者达到大约 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",
        ]);

    }

【问题讨论】:

  • 这只是机器人中的一个示例代码,我向用户发送消息,向您展示我是如何编写代码的

标签: php telegram telegram-bot php-curl php-telegram-bot


【解决方案1】:

我认为,问题是由 PHP 中的执行时间限制引起的。默认情况下,脚本运行 30 秒,但可以增加。

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

【讨论】:

    猜你喜欢
    • 2018-02-04
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 2017-10-24
    • 2017-03-19
    • 2017-07-17
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多