Z
Z
zheka0072017-09-29 22:27:57
PHP
zheka007, 2017-09-29 22:27:57

Why messages to users from the telegram bot arrive with a delay?

Telegram bot created, users connected. Let's say only the elite (70 people), the bot is not included in the groups. The server processes certain php scripts by cron, and when the desired event occurs (to which the user is subscribed), a notification is sent to the user.
But the problem... not all messages arrive at the right time, there is a delay of 4 minutes. It was even 8 minutes and 12.. it just didn't get into the logs yet...
[29.09.17 20:04:38] | [chat_id]
[29.09.17 20:04:37] | [chat_id]
[29.09.17 20:04:36] | [chat_id]
[29.09.17 20:04:35] | [chat_id]
[29.09.17 20:04:34] | [chat_id]
[29.09.17 20:04:33] | [chat_id]
[29.09.17 20:04:32] | [chat_id]
[29.09.17 20:04:31] | [chat_id]
[29.09.17 20:04:30] | [chat_id]
[29.09.17 20:04:29] | [chat_id]
[29.09.17 20:04:28] | [chat_id]
[29.09.17 20:04:27] | [chat_id]
[29.09.17 20:04:26] | [chat_id]
[29.09.17 20:04:25] | [chat_id]
[29.09.17 20:04:24] | [chat_id]
[29.09.17 20:04:23] | [chat_id]
[29.09.17 20:04:22] | [chat_id]
[29.09.17 20:04:21] | [chat_id]
[29.09.17 20:04:20] | [chat_id]
[29.09.17 20:04:19] | [chat_id]
[29.09.17 20:04:17] | [chat_id]
[29.09.17 20:04:16] | [chat_id]
--- there is a delay of 4 minutes for some reason ---
[29.09.17 20:00:15] | [chat_id]
[29.09.17 20:00:14] | [chat_id]
[29.09.17 20:00:13] | [chat_id]
[29.09.17 20:00:12] | [chat_id]
[29.09.17 20:00:11] | [chat_id]
[29.09.17 20:00:10] | [chat_id]
[29.09.17 20:00:09] | [chat_id]
[29.09.17 20:00:08] | [chat_id]
[29.09.17 20:00:07] | [chat_id]
[29.09.17 20:00:06] | [chat_id]
[29.09.17 20:00:05] | [chat_id]
[29.09.17 20:00:04] | [chat_id]
[29.09.17 20:00:03] | [chat_id]
Here's another example:
[29.09.17 18:34:56] | [chat_id]
[29.09.17 18:34:54] | [chat_id]
[29.09.17 18:34:53] | [chat_id]
[29.09.17 18:34:52] | [chat_id]
[29.09.17 18:34:50] | [chat_id]
[29.09.17 18:34:49] | [chat_id]
[29.09.17 18:34:47] | [chat_id]
--- there is a delay of 4 minutes for some reason ---
[29.09.17 18:30:46] | [chat_id]
[29.09.17 18:30:44] | [chat_id]
[29.09.17 18:30:43] | [chat_id]
[29.09.17 18:30:41] | [chat_id]
[29.09.17 18:30:40] | [chat_id]
[29.09.17 18:30:39] | [chat_id]
[29.09.17 18:30:37] | [chat_id]
[29.09.17 18:30:36] | [chat_id]
[29.09.17 18:30:34] | [chat_id]
[29.09.17 18:30:32] | [chat_id]
[29.09.17 18:30:31] | [chat_id]
[29.09.17 18:30:30] | [chat_id]
[29.09.17 18:30:28] | [chat_id]
[29.09.17 18:30:27] | [chat_id]
[29.09.17 18:30:25] | [chat_id]
[29.09.17 18:30:24] | [chat_id]
[29.09.17 18:30:22] | [chat_id]
[29.09.17 18:30:21] | [chat_id]
[29.09.17 18:30:19] | [chat_id]
[29.09.17 18:30:17] | [chat_id]
[29.09.17 18:30:16] | [chat_id]
[29.09.17 18:30:15] | [chat_id]
[29.09.17 18:30:13] | [chat_id]
[29.09.17 18:30:12] | [chat_id]
[29.09.17 18:30:10] | [chat_id]
[29.09.17 18:30:09] | [chat_id]
[29.09.17 18:30:07] | [chat_id]
[29.09.17 18:30:06] | [chat_id]
[29.09.17 18:30:04] | [chat_id]
[29.09.17 18:30:03] | [chat_id]
When an event occurs, for example if ($a == $b)
the function is called The function
sendMessage_telegram($telegram_chat_id, $message);
itself is in the connect.php file (connection to the database) with bot tokens:

function sendMessage_telegram($telegram_chat_id, $message) {
    usleep(1100000);
    file_get_contents($GLOBALS['api_telegram'] . '/sendMessage?chat_id=' . $telegram_chat_id . '&text=' . urlencode($message));
    $data_sendMessage = date ("d.m.y H:i:s");
    mysql_query(" INSERT INTO `telegram_sendMessage`(`data`,`chat_id`,`text`) VALUES ('$data_sendMessage','$telegram_chat_id','$message') ");
  }

I set a delay before sending to 1.1 seconds. (I thought this should be enough) since the TG API says that you can’t send more than 30 messages per second, but still by ...
After sending, I set a log record when users started complaining that notifications did not come on time.
What can be a jamb? Server Tuning? Botha? php?
Is it a TG block or something else?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Optimus, 2017-09-30
@zheka007

I think that when processing by cron, the next cron runs the script when it has not yet finished processing the previous cron, then again, because of this, there are brakes and delays

N
nllm, 2017-09-29
@nllm

You need to look at the entire bot code, otherwise it will be difficult

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question