Hi there I am creating a community website where if user A visit to profile of user B then it will notify user B that 1 person visited to your profile, if user is offline then it will send email notification that 1 person visit to your profile.
Problem: If I enter a log into database every time user visit to anothers profile… it will show wrong data.. for example if i visited to a user profile and just refresh page many times then it will log many times and i have to use grop by query which is waste of data. So should I use time to something? what will be best approach?
Second, how frequent I send email if user if offline. If i send once i enter log then in a day I am sending many mails to users. What should i follow to keep system spam free and effective?
First:
The data is not wrong! YOU must decide what you want to log! If you want to log only one visit from A to B per Day add a date column to your log and check if thee is already a row With matching “from”, “to” and “date” values before you insert a new row.
This would however create two rows if A visits B at 23:58 and reloads at 00:01.
You can add a datetime column to your log and only insert a row if the timespan between two visits is greater then or equal to 24 hours.
Second:
Let your users choose how often they want to get a notification! You can use cronjobs and/or workers to send the notifications depending on the users settings. I would suggest using one worker to do all the mailing to avoid conflicts, but this highly depends on your server. If you can not set up a dedicated mailing thread you can use multiple cronjobs but then you will have to take into account that a user might change his settings, or get a visitor while your cronjob is still working.
IMHO Sending notification mails more than once a hour for profile visits is a reasons to block all mails from a site. Daily updates should be enough.