PHPackages                             canaan/web-socket - 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. [Framework](/categories/framework)
4. /
5. canaan/web-socket

ActiveLibrary[Framework](/categories/framework)

canaan/web-socket
=================

Laravel library for asynchronously serving WebSockets.

1.6(8y ago)014[1 PRs](https://github.com/canaan5/web-socket/pulls)MITPHPPHP &gt;=5.5.9CI failing

Since Dec 16Pushed 2w ago1 watchersCompare

[ Source](https://github.com/canaan5/web-socket)[ Packagist](https://packagist.org/packages/canaan/web-socket)[ RSS](/packages/canaan-web-socket/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (19)Used By (0)

[![](https://cloud.githubusercontent.com/assets/5102591/22400427/ecfae2ce-e5c5-11e6-8430-16eef73c01a5.png)](https://github.com/TheOrchid/Platform)

Laravel library for asynchronously serving WebSockets.
 Build up your application through simple interfaces and re-use your application without changing any of its code just by combining different components.

[![](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.me/tabuna/10usd)[![](https://camo.githubusercontent.com/11e67a51da19b9ac562f34633e4e2895d7f053fb9923554880dbfcb01f721d4f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30343464393735642d633933342d346432612d396662302d6666646630363564623534352f6d696e692e706e673f32)](https://insight.sensiolabs.com/projects/044d975d-c934-4d2a-9fb0-ffdf065db545)[![](https://camo.githubusercontent.com/6c151cc2867cc37ab78da5c06944e9e341bb6cb48926100b512e9d8afa1f9669/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383130353037312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/48105071)[![](https://camo.githubusercontent.com/f371f572c276051ca5fe4ebc301f730a82b06efe93043a615660d9f10a0648bd/68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f736f636b65742f762f737461626c65)](https://packagist.org/packages/orchid/socket)[![](https://camo.githubusercontent.com/c209ccbb891278a2b11d1357d174d00c9e0184cf21a44ae5529676eecf1b7e8e/68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f736f636b65742f646f776e6c6f616473)](https://packagist.org/packages/orchid/socket)[![](https://camo.githubusercontent.com/5e48ca00f7f13132fac3f3a53c453b379a93afcb238f1e553992f428ec9d92de/68747470733a2f2f706f7365722e707567782e6f72672f6f72636869642f736f636b65742f6c6963656e7365)](https://packagist.org/packages/orchid/socket)

Laravel WebSocket
=================

[](#laravel-websocket)

Socket - full-duplex communication protocol over the TCP-connection for exchanging messages between the browser and web server in real time.

WebSocket is designed to implement in the web-browser and web-server, but it can be used for any client or server application.

Protocol WebSocket - an independent protocol based on the TCP protocol. It enables greater interaction between the browser and the web site, promoting the dissemination of interactive content and the creation of real-time games.

Installation Laravel WebSocket
------------------------------

[](#installation-laravel-websocket)

install package

```
$ composer require orchid/socket
```

edit config/app.php service provider : (Laravel &lt; 5.5)

```
Orchid\Socket\Providers\SocketServiceProvider::class
```

structure

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

### Creature :

[](#creature-)

To create a new listener, you need to

```
php artisan make:socket MyClass
```

In the folder `app/HTTP/Socket/Listener` create template Web listener socket

After creating a need to establish a route which Is located `routes/socket.php`

```
//routing is based on an Symfony Routing Component
$socket->route('/myclass', new MyClass, ['*']);
```

To launch the web-socket, use the command:

```
php artisan socket:serve
```

### FAQ

[](#faq)

#### JavaScript

[](#javascript)

Connecting Web socket in JavaScript

```
var socket = new WebSocket("ws://localhost");

socket.onopen = function() {
  alert("The connection is established.");
};

socket.onclose = function(event) {
  if (event.wasClean) {
    alert('Connection closed cleanly');
  } else {
    alert('Broken connections');
  }
  alert('Key: ' + event.code + ' cause: ' + event.reason);
};

socket.onmessage = function(event) {
  alert("The data " + event.data);
};

socket.onerror = function(error) {
  alert("Error " + error.message);
};

//To send data using the method socket.send(data).

//For example, the line:
socket.send("Hello");
```

#### Authorization

[](#authorization)

Example of installation numbers unique socket and session laravel

```
public function onOpen(ConnectionInterface $conn)
{
    $this->clients->attach($conn);

    //take user id
    $userId = $this->getUserFromSession($conn);

    //Create a list of users connected to the server
    array_push($this->userList, $userId);

    //We tell everything that happened
    echo "New connection! user_id = ({$userId})\n";
}

public function getUserFromSession($conn)
{
    // Create a new session handler for this client
    $session = (new SessionManager(App::getInstance()))->driver();

    // Get the cookies
    $cookies = $conn->WebSocket->request->getCookies();

    // Get the laravel's one
    $laravelCookie = urldecode($cookies[Config::get('session.cookie')]);

    // get the user session id from it
    $idSession = Crypt::decrypt($laravelCookie);

    // Set the session id to the session handler
    $session->setId($idSession);

    // Bind the session handler to the client connection
    $conn->session = $session;
    $conn->session->start();

    //We take the user from a session
    $userId = $conn->session->get(Auth::getName());
    return $userId;
}
```

#### Nginx proxy

[](#nginx-proxy)

```
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    upstream websocket {
        server you-web-site.com:5300;
    }

    server {
        listen 443;
        location / {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;

                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto https;
            proxy_redirect off;
        }
    }
```

#### Supervisor

[](#supervisor)

```
[program:laravel-socket]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/your-path/artisan socket:serve
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/your-path/storage/logs/socket.log
```

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance63

Regular maintenance activity

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~42 days

Recently: every ~105 days

Total

17

Last Release

3178d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2491082?v=4)[Canaan Etaigbenu](/maintainers/canaan5)[@canaan5](https://github.com/canaan5)

---

Top Contributors

[![tabuna](https://avatars.githubusercontent.com/u/5102591?v=4)](https://github.com/tabuna "tabuna (60 commits)")[![canaan5](https://avatars.githubusercontent.com/u/2491082?v=4)](https://github.com/canaan5 "canaan5 (4 commits)")[![dmirogin](https://avatars.githubusercontent.com/u/5470439?v=4)](https://github.com/dmirogin "dmirogin (1 commits)")[![JulienBreux](https://avatars.githubusercontent.com/u/964330?v=4)](https://github.com/JulienBreux "JulienBreux (1 commits)")

---

Tags

phpframeworkweblaravelserverwebsocketSocket

### Embed Badge

![Health badge](/badges/canaan-web-socket/health.svg)

```
[![Health](https://phpackages.com/badges/canaan-web-socket/health.svg)](https://phpackages.com/packages/canaan-web-socket)
```

###  Alternatives

[hprose/hprose

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

2.0k219.1k37](/packages/hprose-hprose)[hprose/hprose-swoole

Hprose asynchronous client &amp; standalone server based on swoole

17929.0k10](/packages/hprose-hprose-swoole)[hprose/hprose-yii

Hprose Server for Yii 2

357.2k](/packages/hprose-hprose-yii)[gdg-tangier/cloud-pubsub

Google Cloud pub-sub for laravel

5056.7k](/packages/gdg-tangier-cloud-pubsub)

PHPackages © 2026

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