Download the PHP package hi-folks/lara-sock without Composer
On this page you can find all versions of the php package hi-folks/lara-sock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hi-folks/lara-sock
More information about hi-folks/lara-sock
Files in hi-folks/lara-sock
Package lara-sock
Short Description WebSocket package for Laravel application, using Swoole or Open Swoole server
License MIT
Homepage https://github.com/hi-folks/lara-sock
Informations about the package lara-sock
LaraSock
This is an early stage (under construction/exploration) work in progress, so currently, the project only implements some of the functionalities you expect. Feel free to share if you want to contribute, providing Pull Request or suggestions. We believe in positive vibes.
Why LaraSock?
Larasock implements a WebSocket Server based on Open Swoole. The final goal is to support the same Application Providers supported by Laravel Octane (Swoole and Roadrunner). This package lets you easily add real-time functionalities via WebSocket to your Laravel/Octane application.
So, if you are already using Open Swoole with your Laravel Octane, you don't need additional services or external tools to enable the Web Socket functionalities.
Installing LaraSock
The LaraSock hi-folks/lara-sock
is provided as a PHP package that you can install in your Laravel project.
To install the package, you can use composer require
command:
Starting the server
Installing the package in your Laravel project adds a new command with php artisan
.
The new larasock:start
artisan command starts a long live running process that starts a Web Socket server, ready to listen and accept your Web Socket connection from clients.
Options
With the command, you can use some options:
The default host is 127.0.0.1
, which means that
it can receive connections from localhost clients.
The default port is 9501
.
If you want to accept connections from all the clients on the network,
you have to "bind" to 0.0.0.0
IP address:
If you have Tmux installed, you can use it to start the Octane Web server and the WebSocket server on the same screen.
The client
Once you start the Web Socket Server, you can create your Web client to send and receive messages. You can implement your HTML page using the WebSocket Javascript class.
A note about the Subprotocol
WebSocket defines a protocol that allows clients and servers to exchange data (messages). A Sub-protocol defines the exchange message's structure and the meanings of each field. For example, you want to exchange a pure string with a text message without additional information. Or you want to exchange data with a more complex structure.
The current implementation of this Proof of Concept exchanges messages in string format.
Next Step, the evolution of the Proof of Concept
This is just a Proof of Concept, the thing that I would like to focus on (and feel free to share any suggestion/feedback/pull request):
- Define the structure of the message
- Allow customising the broadcast method
- Rest API for showing statistics
The package is under construction, so if you have some suggestions, you can:
Contributing
Please see CONTRIBUTING for details.
Submit ideas or feature requests, or issues
The package is under construction, so if you have some suggestions, you can:
- Take a look if your request is already there https://github.com/Hi-Folks/lara-sock/issues
- If it is not present, you can create a new feature request
- Submit a Pull Request
- Write me a message via Twitter
Credits
Who talks about LaraSock
License
The MIT License (MIT). Please see License File for more information.