Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve the pending_update_count problem #709

Closed
NabiKAZ opened this issue Nov 22, 2017 · 12 comments
Closed

solve the pending_update_count problem #709

NabiKAZ opened this issue Nov 22, 2017 · 12 comments

Comments

@NabiKAZ
Copy link
Contributor

NabiKAZ commented Nov 22, 2017

I have two robots on the server and one works well, and another freeze and don't response!
Certainly the config server is same for both.

I was check the https://api.telegram.org/bot.............../getWebhookInfo URL, and was results:

{"ok":true,"result":{"url":"https://......../hook.php","has_custom_certificate":false,"pending_update_count":37,"last_error_date":1511346679,"last_error_message":"Connection timed out","max_connections":40}}

I see pending_update_count was 37.

In another test, I was test this script for my both robots: https://github.com/php-telegram-bot/core/wiki/Bots-watchdog
And my watchdog return:

.. @.................Bot: 37 pending updates;
2017-11-22 14:09:49: Connection timed out

After this test script, it is not told how this problem can be solved. to robot is going up again.

And about Connection timed out, I try to turn off firewall on the server. and so I test by host-tracker.com and was see return 200(OK) from 40 nodes.

How can I solve it?

@chuv1
Copy link

chuv1 commented Nov 23, 2017

It means that Telegram had no answer from your bot in appropriate time.
Try to visit your hook url to see if it's accessible.
If it respond correctly on hook url - check answer time, it could be too high for Telegram servers.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Nov 23, 2017

You can see response web hook and response time.

$ curl https://.........../hook.php
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   340    0   340    0     0    256      0 --:--:--  0:00:01 --:--:--   256exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!' in /home/..../public_html/.........../vendor/longman/telegram-bot/src/Telegram.php:379
Stack trace:
#0 /home/..../public_html/.........../hook.php(183): Longman\TelegramBot\Telegram->handle()
#1 {main}


$ curl https://.........../hook.php
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   340    0   340    0     0    256      0 --:--:--  0:00:01 --:--:--   256exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!' in /home/..../public_html/.........../vendor/longman/telegram-bot/src/Telegram.php:379
Stack trace:
#0 /home/..../public_html/.........../hook.php(183): Longman\TelegramBot\Telegram->handle()
#1 {main}

$ curl https://.........../hook.php
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   340    0   340    0     0    258      0 --:--:--  0:00:01 --:--:--   258exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!' in /home/..../public_html/.........../vendor/longman/telegram-bot/src/Telegram.php:379
Stack trace:
#0 /home/..../public_html/.........../hook.php(183): Longman\TelegramBot\Telegram->handle()
#1 {main}

I thinks everything is normal.

Also, any messages logs will not appear in debug, update, error log file. This means that the request from the telegram falls to my server. So it can not be a problem with the problem of the answer from my robot.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Nov 23, 2017

I test execution time of core my bot:

$ time php test.php

real    0m11.105s
user    0m0.000s
sys     0m0.015s

real    0m14.530s
user    0m0.000s
sys     0m0.015s

real    0m9.839s
user    0m0.031s
sys     0m0.015s

real    0m11.750s
user    0m0.000s
sys     0m0.030s

real    0m11.781s
user    0m0.015s
sys     0m0.015s

So, the time ~11s is very long. this caused because the request to another server for generate photos.

Maybe the problem is this.

I find this docs from another project: http://telegram-bot-sdk.readthedocs.io/en/stable/usage/timeouts/ that talk about timeout and increase it...

Now what's the method for manage timeout in currect project? Why there is not any API reference?!

@noplanman
Copy link
Member

noplanman commented Jan 2, 2018

We don't specify any timeout in the library, so it should wait as long as the maximum script execution time defined by your PHP installation.

You can set a custom timeout in your hook (before ->handle()) by defining a custom Guzzle client though (#536):

Request::setClient(new \GuzzleHttp\Client([
    'base_uri' => 'https://api.telegram.org',
    'timeout'  => 120, // in seconds
]));

I suggest you optimise your application to process requests better.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Jan 24, 2018

I try it, but when call hook.php directly in browser, the watchdog return this error:

ErrorException - Class 'Request' not found;

or

ErrorException - Call to undefined method Longman\TelegramBot\Request::setClient();

And so the bot does not response me.

@noplanman
Copy link
Member

Use \Longman\TelegramBot\Request instead.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Jan 26, 2018

@noplanman I try it before, as you can see the second error message in above.

@noplanman
Copy link
Member

What version of the bot are you on? Maybe you need to upgrade to have the setClient functionality.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Jan 27, 2018

I update and don't get error in hook.
But already there is my problem.

https://api.telegram.org/bot...................../getWebhookInfo
{"ok":true,"result":{"url":"https://............./hook.php","has_custom_certificate":false,"pending_update_count":9,"last_error_date":1517082003,"last_error_message":"Connection timed out","max_connections":40}}

I create this sample command, but don't response from bot:

class SampleCommand extends SystemCommand
{
    protected $name = 'sample';
    protected $description = 'sample effect';
    protected $usage = '/sample';
    protected $version = '1.0.0';

    public function execute()
    {
        $data = [
            'chat_id' => $this->getMessage()->getChat()->getId(),
            'text' => 'under construction.',
        ];
        return Request::sendMessage($data);
    }
}

I thinks must clear and empty pending_update_count. But how?

@noplanman
Copy link
Member

@NabiKAZ Have you been able to fix this? Maybe it was a temporary issue with the Telegram servers?

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Apr 14, 2018

Thanks for following issue again. 💘
I've worked a lot of times on this topic several times.
It looks like the problem is from the firewall server side.
But what caused me not to doubt the firewall was that I had another robot with a structure very similar to the problem robot on that server, which works well and so should not be a problem from the server side.
But apparently, each time I reset the firewall, the messages of robot arrive at destination.
The more surprising thing is that the problem is not resolved by turning off the firewall and it's not important whether the firewall is active or inactive! Rather, I just have to restart the firewall with csf -r command!
It seems like the firewall only needs a shock!!!
It's so strange and confusing! 😖

@noplanman
Copy link
Member

Hmm, so strange 🤔

Well, I'll close off here, as this doesn't seem to be a library issue.

Not really sure what other suggestions I can give you to try, that might help solve this, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants