What is WebSocket ?
– WebSocket connection is a continuous connection between a browser and the server.
– It provides a bidirectional communication: the server can send messages to the browser and the browser– the client – can respond back via an equivalent connection.
– This differs from regular Ajax, which is single one-way communication: only the client can ask stuff from the server.
Why we need WebSocket?
– Because PHP itself does not support WebSocket,
– We need a layer of indirection to send “server” data to the “client”. In other words, real-time communication can be roughly divided into two steps:
– It is built using ratchet PHP library
How WebSocket Works?
– When you start the start a Ratchet server that starts listing for connections
Features of WebSocket:
1. Real -Time apps
– Chat application
– E-commerce application
– Videoconference applications.
2. Pusher Replacement
3. Persistent connection
4. Easy Customization options
5. Debugging dashboard
6. Integrated WebSocket and HTTP Server
– PHP >= 7.1.3
– Laravel >=5.7
Guide -How to install:
Table : websockets_statistics_entries
Table : messages
Install the official Pusher PHP SDK
composer require pusher/pusher-php-server “~3.0”
Change broadcast driver in .env file
In the config/app.php file uncomment
The package will use the pusher driver, but we don’t actually want to use Pusher. Therefore we add our own host and port configuration to ‘pusher‘ section in config/broadcasting.php
Laravel WebSockets package comes with individual Pusher API implementation,
we need to notify Laravel to send the events to our own server.
Also Change in .env file beacuse we are not using pusher
Configuring WebSocket Apps
you can host separately from your current Laravel application server
we can add mutiple application with one laravel websocket server
npm install –save laravel-echo pusher-js
Uncommnet the laravel-echo configuration from Resources/js/bootstrap.js
wsHost and wsPort point them to your laravel WebSocket server host and port.
Starting the WebSocket server
php artisan websockets:serve
php artisan websockets:serve —port=3030
php artisan websockets:serve —host=127.0.0.1
Websocket package dashboard is like pusher’s debug console dashboard. Default Root path of dashboard demo app is /laravel-websockets which is automatically accessible.
– This package comes with different statistic solution
– That will give you current status of your WebSocket server.
– Realtime Statistics
– All Event Details
– The Laravel WebSockets package use pusher key and app id but this package use own server to send and received request that’s why this called pusher replacement package.