What is Laravel-websockets?

Laravel WebSockets is a php package for Laravel 5.7 and up, which handles the server-side of WebSockets for you. It has a web-server, implemented in PHP, that handles incoming WebSocket connections. Laravel WebSockets has been built on top of Ratchet. Also there is support for multi-tenancy, which let you set up a webSockets server and use it for many different applications.

Laravel WebSockets also has a real-time dashboard, that shows you all incoming connections, events and disconnects the moment they happen on your WebSocket server, powered by a real-time chart that gives you key-insights into your WebSocket application metrics, like the number of peak connections, the amount of messages sent and the amount of API messages received.

This package also supports existing packages and applications out there that support Pusher and all the features offered by Pusher, such as private channelspresence channels and even the Pusher HTTP API.

Usage:

1. First, require it with Composer

composer require beyondcode/laravel-websockets

2. Publish the migration file

php artisan vendor:publish–provider=”BeyondCode\LaravelWebSockets\WebSocketsServiceProvider”–tag=”migrations”

3. Run Migrations command

php artisan migrate

4.  publish the config file

php artisan vendor:publish –provider=”BeyondCode\LaravelWebSockets\WebSocketsServiceProvider”–tag=”config”

5. The last step is to fill some environment variables. Make sure that APP_NAMEPUSHER_APP_IDPUSHER_APP_KEYPUSHER_APP_SECRET are filled in your .env

6. start the server by executing this command.

php artisan websockets:serve

Now you can use a library like laravel-echo to connect to the server. To get started with the client side check out docsthe laravel-echo docs and this demo application.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top