Server-sent events and php - what triggers events on the server?

前端 未结 5 1953
执念已碎
执念已碎 2020-12-07 11:49

All,

HTML5 Rocks has a nice beginner tutorial on Server-sent Events (SSE):

http://www.html5rocks.com/en/tutorials/eventsource/basics/

But, I don\'t u

5条回答
  •  悲哀的现实
    2020-12-07 12:16

    Basically, PHP is not suitable techonology for this sort of things. Yes you can make it work, but it will be a disaster on highload. We run stockservers that send stock-change signals via websockets to dozens thousends users - and If we'd use php for that... Well, we could, but those homemade cycles - is just a nightmare. Every single connection will make a separate process on server or you have to handle connections from some sort of database.

    Simply use nodejs and socket.io. It will let you easily start and have a running server in couple days. Nodejs has own limitations also, but for websockets (and SSE) connections now its the most powerfull technology.

    And also - SSE is not that good as it seems. The only advantage to websockets - is that packets are being gzipped natively (ws is not gzipped), but on the downside is that SSE is one-side connection. You user, if he wants to add another stock symbol to subscripton, will have to make ajax request (including all troubles with origin control and the request will be slow). In websockets client and sever communicate both ways in one single opened connection, so if user sends a trading signal or subscribes to quote, he just send a string in already opened connection. And it's fast.

提交回复
热议问题