0
votes

I'm currently working on a email notification of a social media website, and I want to send users email notification whenever the user is not viewing the site(at least for a certain period,30mins,1h,etc)

I'm considering using a cron job for sending those email notification and fire the cron job every 30 minutes.

Let's say user A commented on user B at 2014/8/13 18:39:00, it would have a row in the comment table of the database base like

comment_user   user_received        comment_send_time                  view_or_not(y/n)  email(y/n)
user_A           user_B             2014/8/13 18:39:00                    n                 n

in my corn job php script, I would check if the interval between the current time and the comment_send_time is greater than 30mins, and is view=n email=nand the cron job is going to send user_B an email notification of the new comment, and after the email being sent successfully, updated the email to n, so that it can prevent sending a redundant email notification.

My concern is if I run the cron job every 30 mins, will it harms the server performance, and will a cron job be a proper way to handle this task and what other options would be

1
What's the reasoning against sending the email as soon as the action happens? I've used a cron job to send emails using PHP (a couple of gotachas, but nothing major), but it was a daily reminder for internal use only.Joseph Duffy

1 Answers

1
votes

Personally, I'd have the job set to run every minute and have the script running a very lightweight sql query to check for new alerts.

If your script is heavy and takes longer to run than 1 minute, then scale it back or performance tweak it.

To answer your question directly, yes, it will affect performance. However, if you have a lightweight script, that hit is negligible. If you're sending out thousands of emails every minute, it's time to scale that gear to it's own server. At that point you should be making money enough to support another server, or you need to rethink your strategy for alerting users. If you need to start scaling, then start looking at message queueing, and task/work queues like RabbitMQ or Laravel