php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.79k stars 949 forks source link

Bot so slow work... #1431

Closed FeST1VaL closed 6 months ago

FeST1VaL commented 6 months ago

Hello everyone

TelegramBot version: 0.81.0
PHP version: 8.0.30 (64bit); fpm-fcgi; Linux
Maximum PHP script execution time: 300 seconds
MySQL version: 10.3.39-MariaDB
Web Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
curl version: 7.29.0; NSS/3.53.1

After restore host vds my bot work so slow... in request.log i see /hook 200 response... but he can be 1-2 min return message after command start...

Server on CentOS7, i wasnt change my configuration... only changes IP.

In debug.log from TelegramLog i see so many telegram_bot.DEBUG: Duplicate update received, processing aborted! [] [] In /getWebhookInfo "last_error_message": "Read timeout expired", but if i add logs to startcommand file they work fine...

Error.log form TelegramLog::error

[2023-11-14T18:57:30.168015+03:00] telegram_bot.ERROR: START COMMAND START [] []
[2023-11-14T18:57:30.175454+03:00] telegram_bot.ERROR: START COMMAND END [] []
[2023-11-14T18:57:30.175614+03:00] telegram_bot.ERROR: START COMMAND SENDDATA:  [] []

Request.log form httpd

91.108.6.43 - - [14/Nov/2023:18:58:30 +0300] "POST /hook HTTP/1.1" 200 - "-" "-"
91.108.6.43 - - [14/Nov/2023:18:57:29 +0300] "POST /hook HTTP/1.1" 200 - "-" "-"
91.108.6.43 - - [14/Nov/2023:19:09:17 +0300] "POST /hook HTTP/1.1" 200 - "-" "-"
91.108.6.43 - - [14/Nov/2023:19:08:17 +0300] "POST /hook HTTP/1.1" 200 - "-" "-"

My StartCommand

public function execute(): ServerResponse
    {
        try {
            TelegramLog::error("START COMMAND START");
            $message = $this->getMessage();
            if ($message) {
                $from_values = $message->getChat();
                $user_name = $from_values->getFirstName().' '.$from_values->getLastName();
                $telegram_login = $from_values->getUsername();
                $chat_id = $message->getChat()->getId();

                $container = Container::getInstance();
                //$db = $container->get(Database::class);

                $this->home_callback = $container->get(HomeCallback::class);

                $this->initUser($chat_id, $telegram_login);

                $reply = $this->home_callback->getKeyboard(false);
                $values = $this->home_callback->getValues();
                if ($values === null) {
                    TelegramLog::error("NOT FOUND VALUES -> EMPTY RESPONSE");
                    return Request::emptyResponse();
                }

                $text = $this->convertString($values['start_message']);
                $photo = Request::encodeFile(PUBLIC_ROOT.$values['start_photo']['urls']['full']);

                TelegramLog::error("START COMMAND END");

                $sendData = [
                    'chat_id' => $chat_id,
                    'caption' => $text,
                    'reply_markup' => $reply,
                    'photo' => $photo,
                ];

                TelegramLog::error("START COMMAND SENDDATA: ".json_encode($sendData));

                return Request::sendPhoto($sendData);
            }

        } catch (TelegramException $e) {
            // log telegram errors
            //echo $e->getMessage();
            TelegramLog::error($e);
        }

        return Request::emptyResponse();
    }