PHP websocket real-time message push
The implementation steps are as follows:
1. Get the GoEasy appkey.
Register an account on the goeasy official website and create a new app. After the APP is created The system will automatically generate two keys for the app, one can be used for both receiving and pushing (supper key), and the other can only be used for receiving (subscriber key).
2. The client subscribes to a channel.
a. Introducing goeasy.js on the client, js address: cdn.goeasy.io/goeasy.js
It should be noted that goeasy.js cannot be downloaded locally, because goeasy will download it according to different browsers Provide different js. There are also corresponding instructions on the official website.
b. Subscription code
1 2 3 4 5 6 7 8 9 |
|
3. Frontend push and background push
3.1. Frontend push to the same channel
In the page where goeasy.js is introduced, directly call goEasy .publish('csdnNotification', 'Your friend 222 is online'); Usage is similar to subscription.
3.2. The background pushes to the same channel. Use the restful API provided by GoEasy to implement
API url: goeasy.io/goeasy/publish
Method: Post
Parameter list:
1 2 3 |
|
Hope it helps everyone.
The above is the detailed content of PHP implements front-end and background real-time push based on websocket. For more information, please follow other related articles on the PHP Chinese website!