简体   繁体   中英

PHP, MySql, JavaScript - Pushing data from server to client (Live chat)

I am trying to create a social network with live chat system, so that users can have notification that they have a new message or receive a message after it was sent from another user in real time.

I am new to this, I have made front end (div that will hold messages that are fetched from DB, in form of a paragraph) and DB design, but I am not sure what to use for back end. My best solution so far is to make Ajax call for every user in every few seconds interval, but this looks like inefficient solution for many registered users.

I have searched the web and haven't found any good and up-to-date solutions and I would appreciate if someone could share some experience or point me in the right direction.

Few ways to do it:

websocket (with socketio it's the best)
Server Sent Event Long Pooling Pooling (Ajax)

The best now is websocket . But you can have some problems if your chat needs to work behind some firewall. But the overall perf if you use websocket , you will use something like 80% less resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM