how to send global alert to all users in php application?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krishna.p
Forum Newbie
Posts: 19
Joined: Fri May 23, 2008 8:12 am

how to send global alert to all users in php application?

Post by krishna.p »

Hi Experts,
Is there a way an admin user can send an alert message to all the users who are currently working on the application. for example, 2 users are working on my application. Now admin user logins into my application and enter some text like "This application will not be available for the next 2 hours. Sorry for the inconvience." in a textbox and clicks on SEND button.
In this scenario, the 2 users who were currently logged in should get that alert as soon as admin user clicks on SEND button.
Would appreciate if you guys can help me out in solving this problem. Thanks in advance.
krishna.p
Forum Newbie
Posts: 19
Joined: Fri May 23, 2008 8:12 am

Re: how to send global alert to all users in php application?

Post by krishna.p »

McInfo wrote:When the admin sends an alert, store it in a database. Have your application retrieve new alerts when a user requests a page. This would not be instantaneous since the user would see the alert only if he refreshes or navigates to a new page. If you want the alert to be semi-instantaneous, use an Ajax script to poll the database for new alerts at regular intervals.
Thanks for the reply. if i use the ajax script to poll the database for new alerts at regular intervals i think it would cause a heavy load on server right? would appreciate if you can give me some pseudocode on how to pull the alert from database. thanks in advance.
krishna.p
Forum Newbie
Posts: 19
Joined: Fri May 23, 2008 8:12 am

Re: how to send global alert to all users in php application?

Post by krishna.p »

McInfo wrote:
krishna.p wrote:if i use the ajax script to poll the database for new alerts at regular intervals i think it would cause a heavy load on server right?
This is true. However, because the client-server connection is stateless, the only way the server can send something to the client is if the client asks for it. You can minimize the load by decreasing the polling rate and streamlining the code, but it is probably best to display alerts only when the user refreshes or visits a new page if possible.
krishna.p wrote:would appreciate if you can give me some pseudocode on how to pull the alert from database.
First, there are some questions that need to be answered.
  • Should the admin be able to post-date an alert so it will not appear right now but at a later time?
  • How persistent should the alerts be? Should they display only once, a set number of times, or always until they expire?
  • When should alerts expire -- at a fixed date/time, after some period of time, other?
  • Should alerts display for logged-in users only, for everyone, or can the admin specify who can see an alert by group or individual?
Thanks for the reply. i have answered your questions one by one. Please check it.
[*]Admin can open the global alert screen whenever necessary and clicks on SEND button of that particular screen.

[*]The alert will come only once. i.e.. the logged-in user will see the alert message only once.

[*]after a fixed date/time. i.e.. admin will enter global alert message in a textbox and select the date range(start date and end date) in which that alert should be active and clicks on SEND button.

[*]alerts should only be displayed for the logged-in users.

Please send me the pseudocode to fix my issue. Thanks in advance.
Post Reply