skip to Main Content

So I have a .php script where it checks the database for a date/time and if that date and time is within the next 30 min, then it will send them an email notification.

$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
...
sendEmailReminder($userId);

I’m running a cron job of this script every minute to make sure the email reminders are being sent out for people who have a meeting within the next 30 min. But I feel like this is using a lot of server resources because I have to run this every minute. What do the “big” sites use to check and send reminders out?

There must be a better way of doing this. Thanks!

2

Answers


  1. if you have a large amount of data you have to use one of the queueing systems like
    beanstalkd
    https://beanstalkd.github.io/

    https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf

    redis

    https://redis.io/commands/rpoplpush

    once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs

    Login or Signup to reply.
  2. The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.

    But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).

    Then if true, execute this script

    $stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);

    ELSE, do nothing.

    Execute this script each minute with CRON.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search