Omar Abdelaziz
Omar Abdelaziz

Reputation: 547

why do you need to use a third party server for websockets

I saw this answer why do I need a third-party server for websockets about using a third-party server for WebSocket but I didn't understand what the meaning of Laravel itself is not a WebSocket server and when working with a service like pusher then the connection between my server and pusher is through HTTP but the connection between pusher and client is through WebSocket

Upvotes: 0

Views: 1142

Answers (1)

PunyFlash
PunyFlash

Reputation: 1086

WebSocket server uses UDP to broadcast events to your clients, so you need infinity cycle where you handle incoming events from your server and clients.

Laravel however was designed for PHP - where new daemon created for each incoming request over HTTP (which is TCP). You may trigger some events in your app and throw them for your socket server by TCP, which then will broadcast it over UDP for all your clients.

This is not quite comfortable to mix things up in PHP like in Node.JS where you may have full access to web server in single process. That's why you need external process for WebSockets with Laravel. It may be the same server, but you're required to use UDP for sockets, that's all.

P.S.: The term "third-party server" in this context was probably caused because PHP apps in a lot of cases hosted on virtual hostings, not on a server directly. And usually hostings don't give you the ability to spawn long staying processes.

Upvotes: 1

Related Questions