Laravel WebSockets

We know that WebSocket is a communication protocol that providing a full duplex communication channel i.e. a two way interactive communication channel  over a single TCP connection. The WebSocket  protocol  activates the communication between a  web browser and a web server with lower overhead. These protocols are used in our daily life in chat applications. The chat applications works as follows. The web browser creates a WebSocket connection to the server while the server maintains the open connection. Many other users also uses also use the chat applications at the same time so now the server is having multiple open connections.  The first user sends a message to the server via open connection. The server sees the message coming through first connection and sends the message to all other users. The other users get the message on their browsers and can perform the same.  Laravel websockets are packages that can handle the server side of the websockets for us. The webserver is implemented in PHP and handles incoming WebSocket connections. Laravel WebSockets is a replacement for Pusher so any packages that works with Pusher will work with WebSockets. First, require WebSockets with composer.

composer require beyondcode/laravel-websockets

Now publish the migration file that comes with the package.

php artisan vendor:publish--

provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider"--tag="migrations"

Run the migrate command and publish the config file.

php artisan migrate

php artisan vendor:publish--

provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider"--tag="config"

Use the artisan command shown below to run WebSocket.

php artisan websockets:serve

It has a very good debug dashboard.