Creating Real Time Notification System in PHP and AJAX

Creating Real Time Notification System in PHP and AJAX

Ever wonder how social media websites pops up a notification for every action that happen on your timeline?

This real time notification system keeps track of every action you and your friends do on these social channels. Notifications form a big part of the real time engagement feature of these platforms. Even you are not online, you could still receive these notifications. A PHP notification system could be could be easily built using a mix of vanilla PHP and JavaScript. This system provides real time notification in a PHP powered application.


In this article I will show you how to create a simple notification system by using PHP and AJAX. I will also use jQuery and Bootstrap. For the purpose of this article, I’m assuming that you have already signed up on Cloudways which provides and have launched a server with the PHP application.

Let’s get started.

Import Tables in Database

Cloudways has custom-built MySQL manager and you get a pre-built database with every PHP application. Just move to the Application Access area and launch the database manager.

Now run the following query in the SQL box.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
 
SET time_zone = "+00:00";
 
 
CREATE TABLE `comments` (
 
 `comment_id` int(11) NOT NULL,
 
 `comment_subject` varchar(250) NOT NULL,
 
 `comment_text` text NOT NULL,
 
 `comment_status` int(1) NOT NULL
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
ALTER TABLE `comments`
 
 ADD PRIMARY KEY (`comment_id`);
 
 
ALTER TABLE `comments`
 
 MODIFY `comment_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;

This query will create a table comments and its four columns ‘comment_id’ ‘comment_subject’ ‘comment_text’ and comment_status. All user comments will be entered in this database and then the notifications will be generated.

Create Navigation And Form To Display Realtime Notifications

I will use the basic navigation and Bootstrap forms by declaring the CDN. Simple copy and paste the code in the index.php file.