westacks / telebot

Easy way to create Telegram bots in PHP
https://westacks.github.io/telebot/
MIT License
282 stars 44 forks source link

Guzzle ConnectionException #23

Closed Versud closed 3 years ago

Versud commented 3 years ago

В последнее время бот стал часто вылетать с исключением:

cURL error 7: Failed to connect to api.telegram.org port 443: Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.telegram.org/{bot}/getUpdates

Полез в конструктор класса TeleBot для того, чтобы прокинуть конфиг для таймаута в GuzzleHttp\Client, но это нельзя сделать.

Предлагаю либо ввести возможность установки своего экземпляра GuzzleHttp\Client, либо увеличить таймаут, т.к. 0 секунд по умолчанию - это мало.


Recently, the bot began to crash frequently with an exception:

cURL error 7: Failed to connect to api.telegram.org port 443: Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https: //api.telegram. org / {bot} / getUpdates

I got into the constructor of the TeleBot class in order to edit the config for the timeout in GuzzleHttp\Client, but this cannot be done by librarys config.

I suggest either to introduce the ability to install your own instance of GuzzleHttp\Client, or to increase the timeout, because 0 seconds by default is not enough.

punyflash commented 3 years ago

Мысль про кастомизацию HTTP клиента звучит вполне оправданно - это позволило бы расширить настройку guzzle, хотя острой необходимости в этом и нет, поэтому сам я это делать не буду. С радостью приму pull request, если кто-либо возьмется доработать это.

В вашей же проблеме увеличение параметра connect_timeout не поможет, т.к. значение 0 по умолчанию задает неопределенное количество времени. Другими словами - пока запрос не закончит обработку. Если бы ошибка была связана с этим, то ее код был бы 28, а не 7. Вы видите эту ошибку по одной из следующих причин:

  1. Нестабильное соединение вашего сервера/рабочей станции с сетью
  2. Вашему серверу заблокирован доступ к api.telegram.org (Telegram не работает в некоторых странах)
  3. Высокая нагрузка или другие проблемы на стороне серверов Telegram (что маловероятно, ни разу не наблюдал никаких проблем с их стороны)

The thought of customizing the HTTP client sounds quite reasonable - it would allow expanding the guzzle setting, although there is no urgent need for this, so I will not do it myself. I would gladly accept a pull request if anyone can tweak this.

In your problem, increasing the connect_timeout parameter will not help, because the default value of 0 specifies an indefinite amount of time. In other words - until the request finishes processing. If error was associated with this, then its code would be 28, not 7. You see this error for one of the following reasons:

  1. Unstable connection of your server/workstation to the network
  2. Your server is blocked from accessing api.telegram.org (Telegram does not work in some countries)
  3. High load or other problems on the side of Telegram servers (which is unlikely, I have never observed any problems on their part)

Related

https://github.com/php-telegram-bot/telegram-bot-manager/issues/66 https://github.com/irazasyed/telegram-bot-sdk/issues/472

Versud commented 3 years ago

Спасибо за разъяснение. Моя недоработка в том, что не посмотрел поведение Guzzle при connection_timeout=0