I am stuck with algorithm to mail notifications for users. Website is built on PHP 5.4 and MySQL 5.5 .
I have simple one-to-one messaging system built on the site I am working on, and these messages are stored in a database. The task is to send daily email at 9:00am with notification if user has some unread messages waiting for him.
The way how I accomplished it by now is this:
I run the script with cron (every 10 minutes) to collect rows after the last ID of checked message (ID is stored in 'notifications_work_table') from 'messages_table';
according to collected data, I count how many unread messages has each user on that database and then I make personalised message for each user, and store that message in 'mailing_queue_table' and setting the time to send this message at tomorrows 9:00am (if its past 9:00am this day), or to todays 9:00am (if it's past midnight this day). On 'notifications_work_table' ID is updated to last checked message id;
in parallel I run another script with cron (also every 10 minutes) to check if there are any messages to send, if the now() time is past to time when I need to send the message from 'mailing_queue_table'. In one try I send only 100 email messages.
The problems starts there, when user is online and is reading messages already on the fly. For example, user receives a message on 8:05, script, that collects unreads count (1st point) runs on 8:10, but user then reads this message on 8:12, then stored personalised message (3rd point) has false information laying there, and then I have to run again delete query to unset it from queue.
While writing this problem, I had a thought about that I could check for that if user has been online in some sort of interval, and then check should I send him a notification, or he is so active on site, that there is no necessary to store on queue and then send the mail.
Maybe you have some good literature or tutorial to do these things properly. For example, Facebook is great example of sending notifications, but good material is hard to find. Maybe you have some ideas, that you have went through in your programming life and could share with us.
Thanks,
/Rob
Related
Actually my requirement is that, I have to send email after some (pre-defined) time interval (which is set by Admin through admin panel etc) like "After every week" or "every fortnight" or "every month" or "daily".
I have inserted all data i.e users email info etc and the time interval after which email notification is to be sent in Database.
Now I am required to run a script in cron job to send email notifications to users with their respective (repeating) time interval (set by admin and stored in DB). I am confused how to do so.
So can anyone kindly help me out to resolve this problem. Thanks in advance.
You can just create a regular PHP script that first gets the users and the interval from the database and then sends the e-mails. Then you should call this script on a time interval (for example every hour) and check whether it should execute (so whether the interval time has passed since the last execution time, which you should also store. Most hosts have information on how to set up cron jobs.
I am working on a web-application to make an SMS Reminder service, which takes various inputs from the user, like the user's name, his number, and the time he wants the reminder. The reminder is then sent through an SMS. I have the SMS Gateway part figured out for which I am using Zeep Mobile's API. I wanted to know how I can send an SMS on the time input by the user.
The database would have the user-id and the time, and I need to get my application to send an sms at the time. Any tutorials on similar lines would be great help.
Thanks in advance
Let's say your reminder interval is 1 minute and you are deploying on Linux.
1) Set up a cron-job to check your database every minute for possible reminders
2) If there are reminders to be sent, execute your sending script.
3) Mark sent reminders with a status (or similar) so you don't send them again.
Depending on what server your application is deployed, you would need to run some kind of service that would run continuously and send SMS whenever one is due.
One note though, since repeated database access is costly, you may like to load up Reminders that would need to be sent in a short time. The database should be accesses periodically with a reasonable time interval.
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.
HI all,
I have an account in getresponse.com
I want to send emails to the members in my mailing list after one hour of their joining.
Please tell me how can i do this
I don't really know what's that getresponse.com all about and what are your possibilities, but deducing from php tag:
Php scripts can't execute for an hour => you have to schedule this. You need some database(or at least a file or sth else) to store the information when someone joined and a cron script that's scheduled to run eg. every 5 minutes that checks your database and if the time is right sends an e-mail and then removes the entry from database.
Admin interface allows you to create a follow-up message received by subscriber no sooner than 1 day after their subscription, so you will most likely have to send it through their API call:
http://dev.getresponse.com/api-doc/#send_newsletter
i have a program which use to send group emails, i set a cornjob per mins for this program, and set execute per 2nd/min, and check if the now time is match to my defined schedule time in db. if true the program will run and send email, else nth...
the problem is i want to dynamic set the amount of email sending per mins by user, let say i have 10000 emails to send, and i want to send 3 emails per min, something like that, but i cant find the way when using cronJob, (set cookie? record the current email to db?),
since i found that if i use sleep(), it will cause php execute limit error...
Can anyone tell me how to do that?
or using other method to do schedule task? pear?
if using other methods, can show how to use it briefly ?
Please And Thx
First of all. 10000 emails with 3 per minute will take over 2 days.
Secondly, the best way to do this is to save the emails to database (to, title, body etc) and then create a script that sends out 3 emails and set the cronjob to run every minute.
Also check out these questions.
Sending bulk email in PHP
Sending mass email using php
Best way to send 10,000+ emails with PEAR/Mail_Queue
I think you should set this configuration at the application level rather than the cron job level.
Let's say, cron job should run every minute but the application itself should know howmany e-mails to send when a cron job runs by checking the datetime for the last e-mail is sent, and let's say, send 3 more e-mails and so.
its only example to said 3 emails per mins
actually i want to give user to set the amount of sending email per min/ per hour/ per second
and i know about the send email program, but what if mutil task doing..
such as 3 newsletter will blast at 20/3/2009 15:15:00; each of those target to 10000pls
i dun want to save the whole blast list in db, since client may import a email list for 40000 ppls, always timeout when import, even i set the time limit to 2 mins, dun want to take more then that time
so do u have any sugeestion on the email sending?