Have you ever wanted to use Websockets without using an external service like Pusher? In this video I will show you how you finally can leverage the power of websockets in Laravel without any external services. We will use Laravel Echo to work with the sockets on the frontend and Laravel events to trigger events on the server side.
The method we will use to operate our Websockets today is a package called laravel-websockets. This package actually imports an instance of Ratchet, a low-level web sockets server, into our Laravel project to allow us to host a websocket server as part of an existing Laravel application. This is convenient because everything is self-contained in one Laravel application.
You can run this web socket server inside the Laravel app that requires web sockets, or you can choose to host a standalone application that runs this package for your own self-hosted websocket platform. It can support multiple clients just like other popular websocket services.
This package scales well, with over 15,000 concurrent connections maintained using just a simple 512Mb ram VPS server that usually costs around $5 a month.
▼ ▼ ▼ LINKS ▼ ▼ ▼
Next (Optional): Configuring Laravel-Websockets – Understanding the settings:
Learn Websockets in Detail with My Full (FREE) Course on YouTube:
Does This Package Scale?:
▼ ▼ ▼ CODE SNIPPETS ▼ ▼ ▼
This was a straightforward setup tutorial, so no GitHub repo is provided.
To install in an existing Laravel app
1) Install via composer:
composer require beyondcode/laravel-websockets
2) Publish migration files:
php artisan vendor:publish —provider=“BeyondCodeLaravelWebSocketsWebSocketsServiceProvider” —tag=“migrations”
3) Publish Configuration Files:
php artisan vendor:publish —provider=“BeyondCodeLaravelWebSocketsWebSocketsServiceProvider” —tag=“config”
4) Run Migrations:
php artisan migrate
To start your web socket server run:
php artisan websockets:serve
==== FOLLOW ME ====
Subscribe for New Releases!
Subscribe to DevMarketer Insider
(ask me questions!)
==== QUESTIONS? ====
Leave a comment below and I or someone else can help you.
For quick questions you may also want to ask me on Twitter, I respond almost immediately.
Email me [email protected]
Thanks for all your support!