PHPackages                             inhere/websocket - 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. inhere/websocket

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

inhere/websocket
================

a lightweight webSocket application library, server and client by sockets,streams,swoole

0.5.1(9y ago)4371MITPHPPHP &gt;=7.0.0

Since Apr 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/phppkg/websocket-server)[ Packagist](https://packagist.org/packages/inhere/websocket)[ Docs](http://github.com/inhere/php-webSocket)[ RSS](/packages/inhere-websocket/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

webSocket application
=====================

[](#websocket-application)

a lightweight webSocket application library

install
-------

[](#install)

in `composer.json` add:

```
"inhere/websocket": "dev-master",

```

run: `composer up`

usage
-----

[](#usage)

### only use webSocket server

[](#only-use-websocket-server)

```
use Inhere\WebSocket\WebSocketServer;

$ws = new WebSocketServer();

$ws->on('open', function (WebSocketServer $ws, $data) {
    $ws->send('welcome!');
});

$ws->on(WebSocketServer::ON_MESSAGE, function (WebSocketServer $ws, $data) {
    $ws->send("you input: $data");
});

$ws->start();
```

### use the webSocket application

[](#use-the-websocket-application)

```
use Inhere\WebSocket\Application;
use Inhere\WebSocket\WebSocketServer;

$app = new Application('', 9501);

$app->onOpen(function (WebSocketServer $ws, Application $app, $id) {
    $app->respond([
        'total' => $ws->count()
    ], 'welcome!');
});

$app->onClose(function (WebSocketServer $ws, Application $app) {
    $app->respond([
        'total' => $ws->count()
    ]);
});

$rootHandler = $app->route('/', new \Inhere\WebSocket\handlers\RootHandler());

// commands
$rootHandler->add('test', function ($data, $index, Application $app) {

    return 'hello';
});
```

webSocket header example
------------------------

[](#websocket-header-example)

### webSocket request header

[](#websocket-request-header)

```
// parsed code
GET / HTTP/1.1
Host: 127.0.0.1:9501
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://localhost:63342
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: _ga=GA1.1.1542925283.1469426767
Sec-WebSocket-Key: Tak3+4p37S5EAltSHDxpTw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

// source code
GET ws://127.0.0.1:9501/ HTTP/1.1
Host: 127.0.0.1:9501
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://localhost:63342
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: _ga=GA1.1.1542925283.1469426767
Sec-WebSocket-Key: BmMdv63hr1D/eS7eTD59Vw==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

```

### webSocket response header(handshake success)

[](#websocket-response-headerhandshake-success)

```
// parsed code
Connection:Upgrade
Sec-WebSocket-Accept:BOVf/XCi92SSib4Ga+ltTsmHiWQ=
Upgrade:websocket

// source code
HTTP/1.1 101 Switching Protocol
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: BOVf/XCi92SSib4Ga+ltTsmHiWQ=

```

license
-------

[](#license)

MIT

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

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

Unknown

Total

1

Last Release

3303d ago

### Community

Maintainers

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

---

Top Contributors

[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (75 commits)")

---

Tags

php-libraryphp-socketphp-streamswoolewebsocket-applicationwebsocket-clientwebsocket-serversocketslibrarywebsocketswooleStreamswebSocket-application

### Embed Badge

![Health badge](/badges/inhere-websocket/health.svg)

```
[![Health](https://phpackages.com/badges/inhere-websocket/health.svg)](https://phpackages.com/packages/inhere-websocket)
```

###  Alternatives

[cboden/ratchet

PHP WebSocket library

6.4k21.4M239](/packages/cboden-ratchet)[hhxsv5/laravel-s

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

3.9k676.0k10](/packages/hhxsv5-laravel-s)[swoft/websocket-server

swoft websocket server component

16134.1k5](/packages/swoft-websocket-server)[plesk/ratchetphp

PHP WebSocket library

1865.9k2](/packages/plesk-ratchetphp)

PHPackages © 2026

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