PHPackages                             componenta/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. componenta/websocket-server

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

componenta/websocket-server
===========================

WebSocket server, protocol, socket, and connection primitives for Componenta

v1.0.0(1mo ago)001MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/websocket-server)[ Packagist](https://packagist.org/packages/componenta/websocket-server)[ RSS](/packages/componenta-websocket-server/feed)WikiDiscussions main Synced 1w ago

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

Componenta WebSocket Server
===========================

[](#componenta-websocket-server)

WebSocket server, protocol, socket, and connection primitives for Componenta. The package contains the low-level server runtime and application contracts; `componenta/websocket-app` connects it to the Componenta application boot process.

Installation
------------

[](#installation)

```
composer require componenta/websocket-server
```

The package requires PHP `^8.4`, `componenta/config`, `componenta/http`, `psr/clock`, and PSR-11.

Application Contract
--------------------

[](#application-contract)

Implement `WebSocketApplicationInterface` to handle lifecycle events:

```
use Componenta\WebSocket\Application\WebSocketApplicationInterface;
use Componenta\WebSocket\Application\Error\WebSocketErrorContextInterface;
use Componenta\WebSocket\Connection\ConnectionInterface;
use Componenta\WebSocket\Protocol\CloseInfo;
use Componenta\WebSocket\Protocol\Message;

final class EchoApplication implements WebSocketApplicationInterface
{
    public function connected(ConnectionInterface $connection): void {}

    public function received(ConnectionInterface $connection, Message $message): void
    {
        $connection->send($message);
    }

    public function disconnected(ConnectionInterface $connection, CloseInfo $close): void {}

    public function failed(WebSocketErrorContextInterface $context): void {}
}
```

Connections expose immutable connection data and controlled write methods through `ConnectionInterface`:

APIMeaning`$connection->id`Framework connection id.`$connection->remoteAddress`Remote socket address.`$connection->request`Parsed WebSocket handshake request.`$connection->context`Mutable connection context object.`$connection->state`Current connection state.`$connection-&gt;send(Messagestring $message)``$connection->sendText(string $payload)`Queue a text message.`$connection->sendBinary(string $payload)`Queue a binary message.`$connection->close(int $code, string $reason)`Queue a close frame and move the connection toward closing.Write methods return `SendResult`. Check `$result->accepted` before assuming the payload was queued; rejected results include a `$reason` and the current `$queuedBytes` value.

Message Routing
---------------

[](#message-routing)

For applications that only need message dispatch, use `RoutedWebSocketApplication` with a `MessageRouterInterface`:

```
use Componenta\WebSocket\Application\CallableMessageRouter;
use Componenta\WebSocket\Application\InMemoryConnectionRegistry;
use Componenta\WebSocket\Application\RoutedWebSocketApplication;

$app = new RoutedWebSocketApplication(
    new CallableMessageRouter(static function ($connection, $message): void {
        $connection->send($message);
    }),
    new InMemoryConnectionRegistry(),
);
```

`RoutedWebSocketApplication` adds connections to the registry on connect, delegates incoming messages to the router, and removes connections on disconnect. Application exceptions are reported through `SafeWebSocketApplicationInvoker`, which calls `WebSocketApplicationInterface::failed()` instead of letting handler failures escape the server loop.

Configuration
-------------

[](#configuration)

`WebSocketOptions::fromConfig()` reads keys from `Componenta\WebSocket\Config\ConfigKey`:

KeyDefault`HOST``127.0.0.1``PORT``8080``PATH``/ws``ALLOWED_ORIGINS``['*']``MAX_FRAME_PAYLOAD_SIZE``1048576``MAX_MESSAGE_PAYLOAD_SIZE``1048576``HEARTBEAT_INTERVAL_MS``30000``PONG_TIMEOUT_MS``10000``MAX_CONNECTIONS``1024`Additional keys control outgoing buffer size, pending handshakes, idle timeout, shutdown drain timeout, select timeout, and listen backlog.

Registered Services
-------------------

[](#registered-services)

`Componenta\WebSocket\ConfigProvider` registers defaults for:

- `WebSocketServerInterface`
- `WebSocketOptionsInterface`
- `HandshakeInterface`
- `ConnectionFactoryInterface`
- `EventLoopInterface`
- `SocketListenerFactoryInterface`
- `SocketSelectorInterface`
- `WebSocketApplicationResolverInterface`
- `WebSocketApplicationInvokerInterface`

The default server uses stream sockets and a select-based event loop.

Boundary
--------

[](#boundary)

This package does not provide application entry points, `config/websocket.php` loading, or Componenta bootloader registration. Use `componenta/websocket-app` for Componenta application integration.

Supervisor contracts such as `WorkerInterface`, `WorkerRegistryInterface`, and `WorkerMessageBusInterface` are declared here because they describe the socket server runtime. A concrete multi-process supervisor is an application/deployment concern.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

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

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k54](/packages/ecotone-ecotone)[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.9k](/packages/symfony-dependency-injection)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k17](/packages/tempest-framework)[illuminate/contracts

The Illuminate Contracts package.

706130.3M14.2k](/packages/illuminate-contracts)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M108](/packages/mcp-sdk)

PHPackages © 2026

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