PHPackages                             hi-folks/lara-sock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hi-folks/lara-sock

ActiveLibrary[HTTP &amp; Networking](/categories/http)

hi-folks/lara-sock
==================

WebSocket package for Laravel application, using Open Swoole server

v0.0.2(2y ago)25141[1 issues](https://github.com/Hi-Folks/lara-sock/issues)MITPHPPHP ^8.1|^8.2

Since May 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Hi-Folks/lara-sock)[ Packagist](https://packagist.org/packages/hi-folks/lara-sock)[ Docs](https://github.com/hi-folks/lara-sock)[ RSS](/packages/hi-folks-lara-sock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

LaraSock
========

[](#larasock)

[![CI/CD Github Actions](https://camo.githubusercontent.com/f849cc5e7e9ec44f16b2b795fd729ade52b04e2afa8b139218689f25f7669074/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68692d666f6c6b732f6c6172612d736f636b2f7068702d636f64652d7175616c6974792e796d6c3f7374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/lara-sock/actions)[![GitHub last commit](https://camo.githubusercontent.com/ca821aca0ee9cf868f67aea04898754cbbbdca35b856dc2a97dba7ec1c0addf8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f68692d666f6c6b732f6c6172612d736f636b3f7374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/lara-sock/commits/main)[![GitHub Release Date](https://camo.githubusercontent.com/1f9668701d3b10e877a1f440dd9be276b2a213282c1389369118337b61e13686/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f68692d666f6c6b732f6c6172612d736f636b3f7374796c653d666f722d7468652d6261646765)](https://github.com/Hi-Folks/lara-sock/releases)[![Packagist PHP Version](https://camo.githubusercontent.com/a80b6ebc80b819845b9f46e082a07c3b8689331b101e30c3b6ba1ec6fdf9085d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68692d666f6c6b732f6c6172612d736f636b3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/hi-folks/lara-sock)

[![LaraSock](lara-sock.png)](https://github.com/Hi-Folks/lara-sock)

> 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](CONTRIBUTING.md), providing Pull Request or suggestions. We believe in positive vibes.

Why LaraSock?
-------------

[](#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
-------------------

[](#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:

```
composer require hi-folks/lara-sock
```

Starting the server
-------------------

[](#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.

```
php artisan larasock:start
```

### Options

[](#options)

With the command, you can use some options:

```
--host[=HOST]     The IP address the server should bind to [default: "127.0.0.1"]
--port[=PORT]     The port the server should be available on [default: "9501"]

```

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:

```
php artisan larasock:start --host=0.0.0.0
```

If you have Tmux installed, you can use it to start the Octane Web server and the WebSocket server on the same screen.

```
tmux \
    new-session  'php artisan octane:start' \; \
    split-window 'php artisan larasock:start --logchannel=stderr' \; \
    detach-client
tmux a
```

### The client

[](#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.

```

     WebSocket with PHP and Open Swoole

        let echo_service;
        append = function(text) {
            document.getElementById("websocket_events").insertAdjacentHTML('afterbegin',
                "" + text + ";"
            );
        }
        window.onload = function() {
            echo_service = new WebSocket('ws://127.0.0.1:9501');
            echo_service.onmessage = function(event) {
                console.log(event.data)
                append(event.data)
            }
            echo_service.onopen = function() {
                append("Connected to WebSocket!");
            }
            echo_service.onclose = function() {
                append("Connection closed");
            }
            echo_service.onerror = function() {
                append("Error happens");
            }
        }

        function sendMessage(event) {
            console.log(event)
            let message = document.getElementById("message").value;
            echo_service.send(message);
        }

        Message:

```

A note about the Subprotocol
----------------------------

[](#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
------------------------------------------------

[](#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:

- [Write a Feature request](https://github.com/Hi-Folks/lara-sock/issues/new?labels=feature-request&title=%5BFeature+Request%5D%3A++)
- [Submit a Pull Request](https://github.com/Hi-Folks/lara-sock/pulls)
- [Write me on Twitter](https://twitter.com/RmeetsH)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Submit ideas or feature requests, or issues

[](#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
- If it is not present, you can create a new [feature request](https://github.com/Hi-Folks/lara-sock/issues/new?labels=feature-request&title=%5BFeature+Request%5D%3A++)
- [Submit a Pull Request](https://github.com/Hi-Folks/lara-sock/pulls)
- [Write me a message via Twitter](https://twitter.com/RmeetsH)

Credits
-------

[](#credits)

- [Roberto Butti](https://github.com/roberto-butti)
- [All Contributors](https://github.com/Hi-Folks/lara-sock/graphs/contributors)

Who talks about LaraSock
------------------------

[](#who-talks-about-larasock)

- [Teasing Tweet](https://twitter.com/RmeetsH/status/1625631431664836608)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1088d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe3f0e9f35a03ea055996e023bc25cfe408742fe9433f66858b714133da55313?d=identicon)[roberto](/maintainers/roberto)

---

Top Contributors

[![roberto-butti](https://avatars.githubusercontent.com/u/678434?v=4)](https://github.com/roberto-butti "roberto-butti (37 commits)")

---

Tags

buildinpubliclaravelopenswooleswoolewebsocketwebsocket-serverlaravelwebsocketswooleweb socketopenswoolelara-sock

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/hi-folks-lara-sock/health.svg)

```
[![Health](https://phpackages.com/badges/hi-folks-lara-sock/health.svg)](https://phpackages.com/packages/hi-folks-lara-sock)
```

###  Alternatives

[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k676.0k10](/packages/hhxsv5-laravel-s)[denis660/laravel-centrifugo

Centrifugo broadcaster for laravel

113164.7k](/packages/denis660-laravel-centrifugo)[huang-yi/shadowfax

Run Laravel on Swoole.

3511.7k](/packages/huang-yi-shadowfax)[basement-chat/basement-chat

Add a real-time chat widget to your Laravel application.

4983.9k](/packages/basement-chat-basement-chat)[swoft/websocket-server

swoft websocket server component

16134.1k5](/packages/swoft-websocket-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
