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

ActiveLibrary

puff/websocket-server
=====================

Fiber-based WebSocket application for PHP Unison Fiber Framework

00PHP

Since Aug 28Pushed todayCompare

[ Source](https://github.com/php-puff/websocket-server)[ Packagist](https://packagist.org/packages/puff/websocket-server)[ RSS](/packages/puff-websocket-server/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Puff WebSocket Server
=====================

[](#puff-websocket-server)

Fiber-based RFC 6455 WebSocket server for Puff. It reuses `puff/server` for non-blocking TCP I/O and provides strict handshakes, masked frame parsing, fragmentation, Ping/Pong, graceful close frames and ordered per-connection message handling. Composer discovery mounts `Puff\WebsocketServer\WebSocketApplication` automatically.

```
$app = new Puff\Application\Application($config);
$app->run(); // Starts every installed application on one shared event loop.
```

The package publishes `config/websocket.server.php`; its values are available under `websocket.server`. The default endpoint is `ws://127.0.0.1:8791`. Incoming messages are echoed unless `handler` or `routes` is configured.

```
return [
    'addr' => '127.0.0.1:8791',
    'routes' => dirname(__DIR__) . '/app/websocket.php',
    'workers' => 1,
    'max_message_size' => 2 * 1024 * 1024,
    'max_handshake_size' => 16 * 1024,
    'max_headers' => 100,
    'max_pending_messages' => 128,
    'allowed_origins' => ['https://example.com'],
    'protocols' => ['json'],
];
```

An empty `allowed_origins` list accepts any syntactically valid Origin. Configure an explicit list for browser-facing production services. Messages from one connection run sequentially; separate connections can run concurrently.

Routes are grouped by handshake path and then by message event:

```
return [
    '/chat' => [
        'events' => [
            'message.send' => [ChatController::class, 'send'],
        ],
        'lifecycle' => [
            'open' => [ChatController::class, 'open'],
            'close' => [ChatController::class, 'close'],
        ],
    ],
    '*' => [
        'events' => [
            'ping' => [SystemController::class, 'ping'],
        ],
    ],
];
```

Clients send JSON messages such as `{"event":"message.send","data":{"message":"Hello"}}`. Controller arguments are resolved by the application container. The following values are injectable by name or type:

- `data`, `event`, and `path`
- `Handshake $handshake`
- `headers`, `query`, and `cookies`
- `Connection $connection`
- `Server $server`

Arrays and objects returned by controllers are encoded as JSON. Event routing accepts text JSON frames; use a custom `HandlerInterface` for binary protocols.

Custom handler
--------------

[](#custom-handler)

Implement `HandlerInterface` when the connection lifecycle or binary frames require direct control:

```
use Puff\Server\Connection;
use Puff\WebsocketServer\Frame;
use Puff\WebsocketServer\Handshake;
use Puff\WebsocketServer\HandlerInterface;
use Puff\WebsocketServer\Server;

final class SocketHandler implements HandlerInterface
{
    public function open(Handshake $handshake, Connection $connection, Server $server): mixed
    {
        return null;
    }

    public function message(
        Handshake $handshake,
        string $payload,
        int $opcode,
        Connection $connection,
        Server $server,
    ): mixed {
        return $opcode === Frame::BINARY ? $payload : strtoupper($payload);
    }

    public function close(Handshake $handshake, Connection $connection, Server $server): void
    {
    }
}
```

Throw `HandshakeException` from `open()` to reject a connection before the `101 Switching Protocols` response.

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![dcto](https://avatars.githubusercontent.com/u/5618679?v=4)](https://github.com/dcto "dcto (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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