views:

18

answers:

2

I'm creating email notification system on my site to send email to the users who has subscribed the article for new comments... 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?

A: 

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.

Sarfraz
+2  A: 

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.

Patrick