irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.03k stars 670 forks source link

Timeout of sending #693

Closed urtvs closed 1 year ago

urtvs commented 4 years ago

Hi When telegram server have problems your class wait i think by default about 40 sec, so all php scripts are going down.

Is there any way to set up timeout of sending msg?

Thanks a lot!

Xibel commented 4 years ago

Hi urtvs,

Telegram Bot uses guzzle client to communicate with the Telegram API. You can find the timeouts in the code like:

$timeOut = 30, $isAsyncRequest = false, $connectTimeOut = 10

It is a personal choice to lower the timeouts if needed based on your network infrastructure. It is mostly not a good idea to lower the timeouts. The fact that your PHP scripts are going down is something you have to manage yourself in your codebase. If you use a framework like Laravel you have a multithreaded framework where your application will not 'hang' when 1 user causes a 40 second timeout.

urtvs commented 4 years ago

My friend thanks for your answer.

But i get problem again

Uncaught Telegram\Bot\Exceptions\TelegramSDKException: cURL error 28: Operation timed out after 60001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in /..../composer/vendor/irazasyed/telegram-bot-sdk/src/HttpClients/GuzzleHttpClient.php:114

I run CRON job for sending messages. But some time telegram servers goes into time out and number of cron processe accumulate and i 3-5 minutes server is not responging because as i understand there is limitation of running process

So i need to kill sending after 1 minute because cron job starts every minute

For is best solution for my problem? Thanks!