D
D
den94ka2019-06-19 11:18:56
PHP
den94ka, 2019-06-19 11:18:56

How to send messages more than once per minute in Telegram in PHP?

Given: I have a bot in Telegram. It sends messages to users once at a certain time. Usually once a day.
The scheme of work is as follows:
The user registers, a message is sent to him and the time of the next sending is considered (registration date + 86400 (day in seconds)). It is stored in the database.
There is a cron script that runs every minute. There is a simple idea:
1. Select from the database all users whose next message sending time is less than the current Unix time.
2. Send them a message in turn through the loop
. If the messages have a difference in sending at least a minute or two, everything is fine.
The question is:
I want to make multiple messages per minute. It's just that there are some messages that need to be sent literally one after another (with a difference of 10-15 seconds). Just if you make them a difference per minute, then they are sent on average in 70-100 seconds (it all depends on the number of users in the queue, etc.).
In general, the user loses focus and gets bored waiting more than a minute for the next message.
I thought to do it through sleep. But in this case, the delay is reflected in the work of the entire bot - I don’t know why. It starts to respond to buttons with a delay, and so on.
How is it possible to solve this issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleh, 2019-06-19
@linkinkov

Through sleep, this is exactly the solution. If you have a monolithic script, I advise you to work with cron separately and use it in a stream (react-php, there are a lot of examples with it), but it’s better to throw a simple js service in general, which itself will constantly listen to the table and send messages. I also had a telegram bot, I divided it into three parts:
- the bot itself (php)
- notifications (nodejs)
- subscriptions (php)
Notifications, just the same, were on the fact that the table listened and notifications were sent when it changed.
Subscriptions, like yours, were made on the crown, launching every half an hour

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question