When a notification email should be sent? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a number of action a user can preform in a social network website, like adding friends following people and such.
Now these actions are done by Ajax, and the user could easily undo them(when say following someone, the follow link is turned into unfollow and clicking it again -of course- results in unfollowing the user, and it -the link- turning back into follow).
When these actions occur, the user (being followed) is notified by via email. and the code that sends the email is run in the same ajax call.
That results in two problems, one is that the email is sent even if the user decides to unfollow the other person at once. And two, multiple emails are sent if the user hits the follow/unfollow link multiple times.
I thought of using a session variable to store users'actions and then at "some point" check on that variable and preform accordingly. My struggle is in finding that "some point", thought of when the user logs out, but I can't guarantee that the user will actually log out.
any suggestions?

The easiest way I can see to do this is:
Push notifications in a DB table. Also, for users, have last activity column. Check often for any rows in notifications that occured before (user.last_activity + TIME_CONSTANT), pop them from the table, group them, and send off to users.
"often" can be a cron task, or even each request (since the query would be quite simple and quick).

Related

Laravel: Send notification to 1000+ users [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a Social Network type Laravel application where users can comment and follow each other, and subscribe a page/user to get notification whenever a new blog/post has been published by the page.
Suppose, 1000+ users has subscribed to get notification for a page. Now, whenever the page publishes a post, I should send notification to all users who has subscribed.
I have a table for notifications like:-
user_id - the user who has subscribed
page_id - the page who published the blog/post
notification - the notification text (same for all users)
Basically, I want to send the notification to all users who has subscribed to the page. In laravel, I can use loop or chunk for all users to add rows to the database. But I want to know what will be the most robust way to send notification to users in laravel. Thanks.
Definitely consider looking into Laravel's Queue for this. It will give a fine tuned control over how many get sent at once, when they get sent and how to handle the case of failure. I use the Queue + Redis for a lot of very similar functionality. https://laravel.com/docs/5.4/queues

How to create a bot in my website that checks if the user is really online or offline and update his status in the database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
U want the bot ro check every 30 seconds to every single user if they are really online and offline by sending a request and if the bot dont get any respond after 20 sexonds they will update the status on the satabase ro offline.
Like
$con->query("UPDATE users SET status='offline' WHERE username='$username');
I want the bot to check on all users online. Offline users dont need to be checked. It doesnt need to ne a super modded bot. I just need the simplest form of a bot that can perform the following actions.
You cannot send anything to the client without prior receiving a request from it. Thats why its called a client, and the server is called a server, cos he serves.
If we could send data to the browsers without browsers 1st asking us for it, it would lead to a really huge security problem.
Solution
You must implement this in both, the javascript and php, but it is not a simple task.
One solution would be to listen for a user's mousemove with jquery javascript, and than when the user is not moving his mouse for X seconds, you send a http request to the server telling him that the user is AFK.

How do I display all users visiting a webpage? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Not sure if this is too open-ended of a question for StackOverflow but, I'm trying to make a basic chat client using AJAX, php and mysql. Users can send messages to the chat, but they can't see which other users are in the chat. Is there a good way to track which users are viewing a webpage and which have left?
the simplest solution is to have a database that records sessions, or at least a "last logged in" column in your database. once a user has logged in, it should reflect in the database that he or she has logged in using a time stamp. this session should auto expire in a given amount of time (like say auto logout, or in others the "idle" status)
then have an AJAX "heartbeat" to check the database if that user has logged out or expired or idle as well as return a list of un-expired users.

How to make a bot to navigate a site? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Given a product id, associates have to navigate a vendors website, log in, perform a search, in order to get details on a product for a customer.
My employers want a program that can use the product id, and navigate the vendors website, and perform the search and everything to get the information thus saving the associate from having to manually repeat this task every time a customer wants more information about a product.
I know many sites use methods to prevent (CAPTCHA) exactly what I am trying to do. So I do not know if that automatically makes my given project an "evil" one. But I certainly do not have evil intentions, my employers simply want to save associates time on getting information that they are going to get regardless. However, if this is "evil" please explain why, so I can explain to my employers why we should not go down this road. That being said...
How can I make something like this in PHP?
It depends on what site you are trying to access. Many sites have an API that can be used to access data. If that's not the case, you may need to write a program that loads the html using a GET request, parses through the response, and retrieves the information you want. Without more details, that's the best answer I can give.
To start with I'd recommend reading up on cURL and DOM
cURL: http://php.net/curl (for fetching pages, even simulating search form)
DOM: http://www.php.net/manual/en/book.dom.php (to parse the fetched pages)

An achievement system like here on stackoverflow in php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Conceptually speaking how would one go about writing an achievement system for a website using PHP and MySQL?
Is the only real way of doing it is to constantly do MySQL queries to test for achievements and such?
You have two options, and most likely can combine them:
You can have a cron-job that runs every X-minutes, and runs over the database looking at each user and checks if they deserve a new badge.
For example, StackOverflow implements this for the Nice Answer badge. Everytime it runs, it checks how many Answers with +10 upvotes you have, and sees if you need to be awarded another badge. (It sees 5 posts with 10 upvotes and 4 Nice Answer Badges, you get a badge). Jeff has already stated that this means if you get an answer that gets a 10 vote, then downvoted, and then another post gets 10 votes, you won't get a badge.
The second option is event-based triggers. Which are really simply:
$badgeSystem->giveBadge("Some Badge Name", $User_ID);
This can be used for events you know are happening. Like the Autobiographer badge. Chances are the user won't fill out his profile unless the submit button is pressed, so the site could just check if the user has filled out the entire thing, and if they have, and they still need the badge, they get it.
The cron-job should be used for actions that are constantly checked. Things like quantitative goals like visiting the site for 150 days, or editing 500 times.
The event-based trigger should happen when an event will only happen if the user doesa specific action, such as submitting a form.
(You could probably use either for almost any situation. The event-based trigger gives quicker feedback though..)
Another option is to use the API from a gamification platform company such as http://iactionable.com
You might want to consider asking a similar question on meta, to see if Jeff is willing to share any of his lessons learned in this arena. If you do, the question should be specifically about the way SO approached the problem. This question, however, is a perfectly valid question for this site (since it is asking about created a new project, inspired by what was done on SO).
I suspect, though, that the SO team has a job that periodically runs a set of queries to look for new badges to award, and then awards them. This is why badges aren't awarded immediately after the action is taken to earn them.

Categories