简体   繁体   中英

JavaScript + PHP & SSE - Server Sent Events & MySQL

Am I scalable enough?
My goal is to create a MySQL WebRTC module. After researching all of the alternatives for server-to-client communication, SSE is good for pushing MySQL notifications. I want to inevitably replace WebSockets.

Can I really use window.onbeforeunload()?
Socket.IO and Node servers are < lyt > $var < /lyt >, but i cannot rely on my hosting providers for open ports. So I found out SSE is highly compatible, as well as window.onbeforeunload = () => abort(id); Imagine an SQL->PHP->Client Signaling Server

How is the performance?
I don't care about latency, since I am only using SSE for notifications. Web RTC would be for two-way or three-way calls only. SSE for chat, would only need update my poll-counts client-side, and update my sql record server-side.

Thus
I have managed Client<-Server<-MySQL topography, but how do disconnections work with AJAX onbeforeunload (eg: very small json less than 2kb@1kbps) . Reinventing natural heartbeats from sockets, Live audio/video for 2-or-3-way streaming is done with WebRTC, yet may we , RTCDataChannel(id) as to EventSource(MySQL)

???
After brainstorming, I think window.onbeforeunload will do trick if its synchronous, not async. Thus should work really fast, for a good UI. I just want to flush out MySQL Records. So SSE can tell the other users "I'm no longer here"

[ https://caniuse.com/#feat=eventsource]
[ https://caniuse.com/#search=beforeunload]

So, you want to use SSE and MySQL as a signalling server.

Actually, you have the assumption that you need to you MySQL for that, and you don't. I was able to create a reliable signalling server with plain text (it is just a few lines that are being exchanged anyway) instead of a database. See https://github.com/nielsbaloe/webrtc-php .

Regarding your points of attention:

  • SSE is not very scalable, well for a maximum of hundred clients it will be good enough. So, for all my small home-brew projects, it is just fine. Syntacticly SSE and Websockets are the same, so when I want to scale up, the code will be almost the same.
  • I do not understand why you are talking about window.onbeforeunload(). There is no need to use that at all, in fact, do not use it. The SSE takes care of the automatic reloading of the webpage, so absolutely no need to write anything yourself like that.
  • The performance is great, SSE works as fast as websockets, as HTTP/1.1 is used these days, it is exactly the same. Only for "posts" it takes longer because a new socket is opened. There is a small delay from server to client, because the client asks for new information once every few seconds (which I scaled down to 1 second in my project), however as signalling server that doesn't matter, within 2 seconds clients have found each other (instead of say 400ms).

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