I am writing a bot for Telegrams and I want to add a reminder to the user.

EXAMPLE: "The user will select an event through a bot, and when to remind him about it (sets the date and time for sending the message). The bot should send him a reminder at the specified time."

How in PHP to make the script exactly at this time?

Or tell me other ways to solve this problem?

  • set a cron task for every minute and check in php if the time is the same as the current time then send a reminder. - Naumov

1 answer 1

The simplest solution is cron, write down the data in the table and poll it with the specified period. Just think about sampling the SQL so that when the table becomes large it does not work out so that the crowns will be behind the day. And again, as an option, the structure of the table:

  • id [primary key int]
  • careated_at [datatime]
  • send_date [datatime]
  • status [tinyint(1) index]
  • user_id [int(11) index]

The sample will be something like this SELECT user_id WHERE status = 1 AND send_date <= now()

  • +, but datatime -> datetime {or even better timestamp}, and careated_at -> created_at, index on user_id is hardly needed when it does not participate in where, it is more logical to index (status, send_date) - Firepro
  • @Firepro Well, I think we need some data about the user, and if we take the tables, I would add the timestamp + - Shadow33