Websocket is a communication protocol that works over TCP. It requires an internet connection, unless you have some special setup where the server and clients are on the same local network.
Webhook is an entirely different concept. It's not a protocol, just a term for HTTP callbacks. Again, it only makes sense in the context of the internet or some special network.
Can you explain what you're trying to do?
For what it's worth, Laravel has a first-party websocket package called Reverb.
@JussiMannisto in the project i am working on, i need to send real time notification before a month, week and two days of expiry date and since it is an internal project, i do not want to sent it to the internet (Firebase, ...), i want it locally.
As of my knowledge cutoff in October 2023, Laravel 11 has not been released yet, so I will provide a solution based on Laravel 10, which should be applicable to future versions as well.
If you're looking to implement WebSockets in a Laravel application without requiring an internet connection, you can use the beyondcode/laravel-websockets package. This package allows you to run a WebSocket server locally, which means it doesn't require an internet connection to function.
Here's a step-by-step guide to setting up laravel-websockets:
Install the Package:
First, you need to install the package via Composer:
composer require beyondcode/laravel-websockets
Publish the Configuration:
Publish the configuration file using the following Artisan command:
Open the config/websockets.php file and configure it according to your needs. You can set the host and port for the WebSocket server. By default, it runs on 127.0.0.1:6001.
Run the WebSocket Server:
You can start the WebSocket server using the following Artisan command:
php artisan websockets:serve
Broadcasting Configuration:
Ensure that your config/broadcasting.php is set up to use the pusher driver, as laravel-websockets is a drop-in replacement for Pusher: