I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.
Related
I'm creating an app which will allow all users to initiate conversation with page owner using Chat-to-SMS service.
Problem is that I'm not sure how to track conversations since there would be one conversation chain from SMS Provider <-> page owner. When owner clicks reply, it needs to know which session user it needs to send the message to.
Basically, I need to do opposite what is being explained here: https://www.twilio.com/docs/quickstart/php/sms/tracking-conversations
How should I accomplish this? I can't quite wrap my head around this.
Twilio developer evangelist here.
If you are sending all the chat messages to just one SMS number then there is no easy way to tie replies back to the original message. (As a quick experiment, if you open an SMS conversation in your own phone and try to reply to any message that wasn't the latest one, you'll see it's not possible.)
There are workarounds though.
You could, when forwarding the message, generate an ID for it. Then get your page owner to include that ID when responding to that message, that way you can route the message back to the original sender and strip out the ID.
Alternatively, when replying you could always respond to the last message that came in. This relies on there not being much traffic, allowing the page owner to respond before the next message arrives. This is error prone though.
Another alternative is purchasing a new number for each new conversation. You could expire the number after a predetermined amount of time. This is made much easier with Twilio Proxy, which was announced recently and is currently in preview.
Let me know if that helps at all.
I'm currently making a promotion plugin for WordPress where I need to send out e-mails to different press e-mails based on a checkbox-list. My hosting provider has a limit of 200 e-mails/hour, but I don't think I will reach that limit. I know that mailing list providers are recommended, but my plugin has some functions (like making promo codes etc.). Everything is now finished with the plugin, and I only need the function for sending.
I have been searching for solutions, and have been looking at timers in PHP to avoid spam detection. I think I will end up with Cron jobs. I have looked into the built in WordPress cron job function, and will try to use this one.
I have never been using cron jobs before, so my questions is: how can I keep track on which e-mail my plugin has sent to? Do I need a temp table where each row is deleted when sent?
Any other suggestions for my solution would be appreciated!
if(mail(//params))
{
//insert this email id in db
}
you can keep track by inserting email id in to db if email sent successfully.
I am trying to build an online chat application on top of ejabberd, I am using extauth and everything was working fine till now. Now I am facing a problem in sending a message from A user who is not in B's roster (some sort of moderator or stuff), but ejabberd is blocking the message because both users are not connected, I have looked into shared roster feature of Ejabberd but it doesn't work with Extauth, I have also tried to filter packet (if packet is from moderator than simply forward it else do routine processing), but it wasn't successful (Don't know how to forward the packet and stop the execution of hooks).
Please help me how can I achieve this functionality.
Thanks
why not subscribe users to each other (by sending subscribe-subscribed sequence) - it may be temporary only. By subscribing users you will create entries in roster table, which will allow packet delivery. Also, depending on architecture of your chat app maybe try mod_muc?
good reference to all dataflows: http://xmpp.org/
Old forum though, adding the response to help and learn.
In order to bypass the hooks and forward the message , probably following steps might help
Add the hook for 'filter_packet' with more priority
In that do your validations
forward this by calling on 'run' on other hook which you are looking for
drop the package at that point( as other hook on which 'run' is called will take care)
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?
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.
I want to send emails through a web app, for example, reminders of a tasks manager, reminders of birthdays... I want to program a date and an hour, and get the email sent at that moment.
I think I have two options to do this: using cron or sending email with a future timestamp.
Using cron involve to run a command (which will query the database) each one, two o five minutes to check if there are any email to be sent. Or, another way, when I save a new reminder, put a new crontab task (via execute a system command from the web app) at the time indicated. With the first option, I think the server load will be excessive. With second option, I'll have hundreds of crontab tasks, what looks dirty for me.
Perhaps I could send the email at the very moment of creating the reminder, but changing the email timestamp to a date and hour in the future. I know some email servers can manage this (like Mercur for Windows), but, is it a standard? I will use my Gmail account to do this job. And, with this solution, I won't be able to cancel a reminder, because the email has been sent at the moment I created the reminder.
I can use PHP or Ruby (RoR) for server language, so the language isn't important, because both of them can send emails and call system commands. If the solution entails scripting, I can use bash scripts, Perl, Python... (the server is a Linux box).
Which do you think is the best method to accomplish the solution to this problem?
I apologize for my poor english. Thanks in advance.
I don't know if you've looked into this, but since you use GMail I thought you might be interested. Google Calendar has this feature:
Go into GMail.
At the top, click on "Calendar".
On the left is a list of calendars. Each has a small link called "Settings". Follow this link (you may want to create a new calendar for this project).
This brings up a tabbed interface. I think it always brings you to the "Calendars" tab, but if it doesn't, click that tab.
Each of the calendars will have a link next to it called, "Notifications". Click the link for the calendar you want to notify you.
This will bring up a list of settings which you can use to set up notifications by sending an email.
Google's API should allow you to access the calendar to sync it with your application. If it's set to send you an email, it will handle all the email for you.
instead of having a cron job for each reminder (or notification, whatever), you might write everything in a file and periodically (for example every 5 minutes) call a script (e.g. php-script) that reads the file and checks whether to send a notification or not...
you would have the functionality without needing to create a cron-job for every item...
would that be a solution?
regards
Having a cron is a better option then sending out emails with future date stamp. Set a cron to run on periodically and it can send out emails.
We have similar questions.
Sending mass email using PHP
https://stackoverflow.com/questions/215736/how-do-i-send-bulk-mail-to-my-users-in-a-generic-fashion
Read those you will get some ideas.