PHP WebSocket Real-time message push
Here I record how to implement the server-side real-time communication with the client:
The implementation steps are as follows:
1. Get Goeasy Appkey.
Register an account on the Goeasy website and create a new app. After the app is created, the system automatically generates two keys for the app, one that can be used for both receiving and pushing (supper key), and the other to receive (Subscriber key).
2. The client subscribes to a channel.
A. Introducing Goeasy.js to the client, JS address: http://cdn.goeasy.io/goeasy.js
It is important to note that Goeasy.js cannot be downloaded locally, because Goeasy will provide different JS depending on the browser. The official web site also has a corresponding explanation.
B. Subscription code
var goeasy = new Goeasy ({appkey: ' subscriber key '});//I'm using subscriber key here, because I don't need to push any messages on my client, so there's no need to use supper key
Goeasy.subscribe ({
Channel: ' Csdnnotification ',
Onmessage:function (message) {
alert (' meessagereceived: ' +message.content);// receiving a push message
}
});
3. Push the background to the same channel. RESTful API implementations with Goeasy
API Url:http://goeasy.io/goeasy/publish
Mode: Post
Parameter list:
Channel: ' csdnnotification '//must be consistent with the subscribed channel, otherwise the client will not receive the message. So we can also control which clients can receive according to the channel.
Appkey: ' supper key '//must use supper key here
Content: ' BlaBla ... '//What to push
PHP Web Real-time messaging backend server Push technology---goeasy