Notification System in PHP / jQuery

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

  • Call an Ajax request to the database when the page loads? But the problem is that it only checks the page loading. It would be better if it were even in real time, I think it depends on the priority of the message. How will I achieve this?
  • Using cookies?

I am using PHP and jquery.

+4
source share
4 answers

As you said, it depends on the priority of the message.

If notifications are made to the visitor performing an action, it would be easy to link the notifications based on the session.

If notifications are made by other users performing the action (for example, “John did the editing on this page. Click here to view.”), You can use AJAX with a long poll to wait for the notification.

+2
source

You might want to learn COMET programming.

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

Basically, you will have a java script function that is sent to the server to check for notifications, and if it finds something, it calls another script that returns notifications to the client. This has to happen every time so often, and WILL create more traffic and leave more open.

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

+2
source

Something small, I would consider using setInterval in conjunction with jQuery .load to load JSON.

+1
source

Well, AJAX and jQuery can be used to develop a basic notification system. I have fully implemented it here: http://www.cloudways.com/blog/real-time-php-notification-system/

You can follow it step by step and also scale it according to your requirements.

0
source

Source: https://habr.com/ru/post/1382361/


All Articles