Php push notifications

10
PHP Push Notification System Mohammed S Shurrab CTO, Datrios.com CTO, UnitOne.ps

description

How to implement a push notification based system using: PHP/MySQL, Elephant.io, Node.js, and MQTT.

Transcript of Php push notifications

Page 1: Php push notifications

PHPPush Notification

SystemMohammed S Shurrab

CTO, Datrios.comCTO, UnitOne.ps

Page 2: Php push notifications

Pull vs Push!

Pull Push

Web Socket & Socket.IO

Node.js

MQQT Server & Client

PHP & Elephant.io

Ajax

PHP

Page 3: Php push notifications

Architecture

Page 4: Php push notifications

Requirements

Back-end Mosquitto server (http://mosquitto.org/)

Node.js (http://nodejs.org/)

Socket.io module (npm install socket.io)

Zeparser module (npm install zeparser)

MQTTClient (https://github.com/yilun/node_mqtt_client)

Front-end Sockit.IO (http://cdnjs.com/libraries/socket.io/)

jQuery (http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js)

Page 5: Php push notifications

Client code

1. Connect to the node.js server through soket.io (L:5)2. Subscribe to some topic(s) (L:10)3. Listen to any notification for these topics (L:7-9)

Page 6: Php push notifications

Node.js code (1/3)

1. include the required modules (L:1-5)2. Specify the web socket port (L:5)3. Connect to the MQTT server (L:6)

Page 7: Php push notifications

Node.js code (2/3)

1. Listening to a successful socket connection (L:8)1. Listening to a subscribing request from the client (L:9-13)

1. Filtering the web socket data based on the topics (L:11)2. Listening to a notify request from the server (L:15-18)

Page 8: Php push notifications

Node.js code (3/3)

1. Listening to a new notification from the MQQT server (L:21)1. Sent these notification through the web socket (L:23-25)

2. Listening to a successful connection with the MQTT server and sent a test notification every 5 seconds (L:29-33)

Page 9: Php push notifications

DEMO

Page 10: Php push notifications