4

I want to program some sort of notification system. What would be the be the best way to achieve this?

  1. By calling Ajax request call to database on page load? But the problem with this is that it only checks on page load. It would be better if it was even realtime, I guess that depends on the priority of the message. How would I go about on achieving this?
  2. By using cookies?

I am using PHP and jquery.

user478636
  • 3,134
  • 13
  • 42
  • 73

4 Answers4

2

You might wanna look into COMET programming.

This would most likely require you to implement this as a distributed solution depending on your traffic.

Basically you'll have a java script function that goes to a server to check for notifications and if it finds any, calls another script that fetches the notifications back to the client. This should happen every so often, and WILL create a higher traffic and leave more connections open.

Take a look at this thread: Using comet with PHP?

Community
  • 1
  • 1
MilkyWayJoe
  • 9,062
  • 2
  • 36
  • 53
2

Like you said, it depends on message priority.

If notifications are made upon the visitor performing an action, it would be easy to tie in session-based notifications.

If notifications are made upon other users performing an action (e.g. "John made an edit to this page. Click here to view."), you could use long-polling AJAX to wait for a notification.

simshaun
  • 20,601
  • 1
  • 51
  • 69
1

For something small, I would consider using setInterval in combination with jQuery .load to load JSON.

djdy
  • 6,575
  • 5
  • 35
  • 61
0

Well AJAX and Jquery can be used to develop basic notification system. I've implemented it completely here: http://www.cloudways.com/blog/real-time-php-notification-system/

You can follow it step by step and also scale it as per your requirements.

Shahroze Nawaz
  • 552
  • 5
  • 9