0

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

Omar Abdelaziz
  • 477
  • 1
  • 6
  • 16

1 Answers1

1

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.

PunyFlash
  • 1,030
  • 1
  • 6
  • 12
  • that is quite good, so if PHP has full access to the webserver would it be able to mix things up? – Omar Abdelaziz Apr 13 '22 at 14:11
  • Well in theory yes, it is possible if you use the Laravel Octane or Swoole, but PHP still not the best choice for such tasks as you will need to worry about memory allocation all the time. And I'm also not sure if it is yet implemented in Laravel, never tried out as usually run socket server by Soketi - https://soketi.app/ – PunyFlash Apr 15 '22 at 04:07
  • Great thank you I really appreciate your answer – Omar Abdelaziz Apr 15 '22 at 05:22