Email notificiation on different actions
I'm creating email notification system on my site to send email to the users who has subscribed the article for new comments..开发者_如何学JAVA. I would like to know what is the best way to handle with this situation in php. Should I use the mail function just after the database insertion or there is some better ways. Will it slow down the process of adding new comments if there are too many subscribers?
I would create a new database table and add the subscribers that needs notifications to that table. Then run a crontab every 5 minutes that sends the emails to those whose article has been commented. That way you don't have to send it directly thus clogging the user experience with longer loading times.
You can send an email as soon as a comment is inserted into the database or when admin/mod approves from admin side if you such mechanism.
Will it slow down the process of adding new comments if there are too many subscribers?
It will because you will be sending the email to more and more subscribers. However, you might want to consider optimizing your insertion query as well as your code if you can.
精彩评论