No Preview

Rizwan Khan

Posted on 13 January 2019

Real time Messaging System using PHP and Firebase

Hi Friends, Here i am going to share source code of real time one on one messaging system for php application using Firebase Nosql Database. 


We all know php lacks in Real time communication and there are many application running in PHP based Server. So if you are interested to add real time messaging system in your app this is right example for you. We can also use Node.js to do this same kind of thing but for that we also need nodejs compatible server. 


Requiremets..

1 - PHP Application with Login System

2 - Firebase Project

3 - Firebase Admin SDK for PHP. 

      Note : I already added Admin SDK in my package so it is not required now but if you are interested to download it you can composer to download this via 

    composer require kreait/firebase-php ^4.18


To Create a Firebase Project visit https://console.firebase.google.com

1 - Click on Add Project

2 - Select Country and Language and so on. Once your project created click on the project app and then select web option out of 3 options

3 - then open your project and click on authentication

4 - Click on 'Sign in method' Tab and enable Email/Password Authentication

5 - In your firebase project app, on the left side there will be an icon of gear symble click on that and then click on project settings and click on Service Accouts and click on generate a new private key it will download a .json file and place it in your root directory



Now you are ready to download my package form github or you can clone it from this url https://github.com/Rizwan17/messenger.git


Steps to configure it

1 - Creat a Database in mysql(phpmyadmin) phpfirebase

CREATE DATABASE phpfirebase;


2- Create two tables users and chat_record

CREATE TABLE IF NOT EXISTS phpfirebase.users (

id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,

    uuid VARCHAR(36) NOT NULL,

    username VARCHAR(50) NOT NULL,

    password VARCHAR(100) NOT NULL,

    UNIQUE KEY (uuid, username)

);


CREATE TABLE `chat_record`(

    `chat_uuid` VARCHAR(36) NOT NULL,

    `user_1_uuid` VARCHAR(36) NOT NULL,

    `user_2_uuid` VARCHAR(36) NOT NULL,

    UNIQUE KEY (chat_uuid)

);


ALTER TABLE users ADD fullname VARCHAR(100) NOT NULL AFTER uuid;


Now once again back to firebase console click on project overview and then click on web and copy the config code and paste it in inside the project folder phpfirebase/js/config.js file and now you can execute it 



and also watch the video for more clarification



Thanks for coming




24

15K

0

No Preview

Rizwan Khan

India

Coding is an art and I love art

Explore more similar Post

7 Comments

fadly_29

7 April 2020

Why When I Register,But The All Register Data Its Nothing In My Database??

0
REPLY

fadly_29

7 April 2020

Where Its The Config Code? Where Its The Config Code

0
REPLY

habib_ch

6 March 2020

Thanks a lot. I had faced the following errors while running your GitHub code. If anyone else has faced these errors then you can solve them by following ways: 1: Rizwan has posted a code to build MySQL DB, when you run his commands then you can't see an email column in the users table, you have to make it your self. 2: If anyone faces the following exception firestore: PERMISSION_DENIED: Missing or insufficient permissions then solve it by the following solution https://stackoverflow.com/questions/46590155/firestore-permission-denied-missing-or-insufficient-permissions

0
REPLY

chintan1

5 March 2020

one to one chat working fine. i am also find group chat can you share any idea.

0
REPLY

salman001

24 September 2019

Thank you so much sir.

0
REPLY

mahnisschaudhary

18 May 2019

hello sir, i just want to learn how this program works ? could you plz help me out ?

0
REPLY

herve

17 March 2019

please can you send to me source code on my email please can you send to me, source code of this project.

0
REPLY

Rizwan Khan

18 March 2019

you can download it from here https://github.com/Rizwan17/messenger.git

REPLY