3 ms·
I'm a little confused by how this is used. The trivial example provided on developer.mozilla.org is a PHP script that's fully self-contained. As far as I coul
by bkyan 3y ago
I'm a little confused by how this is used. The trivial example provided on developer.mozilla.org is a PHP script that's fully self-contained. As far as I could tell, a self-contained PHP script doesn't provide much value. I would have expected something to happen on the server, like a database record getting updated, which triggers the PHP to send an SSE message to the browser, but how do you trigger that particular PHP instance to send a message? Does the PHP instance just poll the database on a periodic basis? That doesn't seem much better than having the browser poll the web server on a periodic basis...
- roblabla 3y agoYou could have some kind of event system running that pushes the event down to php. For instance, redis has a PUBSUB system, and postgresql has NOTIFY.
- bkyan 3y agoAh, the part that was missing from my mental map was having the PHP instance act as a subscriber in a pubsub system. Thanks!
- teraflop 3y ago> That doesn't seem much better than having the browser poll the web server on a periodic basis... It could indeed be much better for performance. It means the polling happens over a (presumably) low-latency, high-throughput local datacenter connection, and not over the end-user's internet connection over which you have no control. But more importantly, SSE only defines the interface between the web browser and web server. Rather than polling a DB, you could just as well hook the web server up to a more sophisticated pubsub system (although PHP might not be the best choice for that). In that regard, SSE is no different from websockets; the main difference is that it's a simpler protocol to implement, and only works one-way.
- bkyan 3y agoAh, the part that was missing from my mental map was having the PHP instance act as a subscriber in a pubsub system. Thanks!