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

AbandonedSymfony-bundle

snoke/symfony-websocket
=======================

v0.0.2(1y ago)71.8k↓50%4[1 issues](https://github.com/snoke/symfony-websocket/issues)[2 PRs](https://github.com/snoke/symfony-websocket/pulls)MITPHPPHP ^8.1

Since Jul 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/snoke/symfony-websocket)[ Packagist](https://packagist.org/packages/snoke/symfony-websocket)[ RSS](/packages/snoke-symfony-websocket/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (6)Used By (0)

Symfony Websocket Server Bundle
===============================

[](#symfony-websocket-server-bundle)

RFC 6455-compliant Websocket Server Bundle for Symfony 7

installation
------------

[](#installation)

checkout library `composer req snoke/symfony-websocket`

modify `config/packages/snoke_websocket.yaml`:

```
snoke_websocket:
    context:
        tls:
            local_cert: 'path/to/server.pem'
            local_pk: 'path/to/private.key'
            allow_self_signed: true
            verify_peer: false
```

if you do not want to use TLS:

```
snoke_websocket:
    context: []
```

note that websockets without TLS only work on localhost (tho you can still use Stunnel to wrap them into a TLS Connection)

getting started
---------------

[](#getting-started)

### Starting the WebSocket Server

[](#starting-the-websocket-server)

Use the Symfony console command to start the WebSocket server

`php bin/console websocket:start`

You can optionally specify the IP address and port:

`php bin/console websocket:start --ip=127.0.0.1 --port=9000`

[![](./Docs/Images/serverstart.png)](./Docs/Images/serverstart.png)

### testing the server

[](#testing-the-server)

you can connect and send a message to your websocket server with following command:

`php bin/console websocket:test`

[![](./Docs/Images/servertest.png)](./Docs/Images/servertest.png)

### Registering Event Listeners

[](#registering-event-listeners)

to react to WebSocket events, create your own listeners.

```
use Snoke\Websocket\Event\MessageReceived;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: MessageReceived::class, method: 'onRequestReceived')]
final class MessageListener
{
    public function onRequestReceived(MessageReceived $event): void
    {
        $connection = $event->getConnection();
        $connection->send("Salutations, intergalactic sphere!");
    }
}
```

test again with `php bin/console websocket:test`

[![](./Docs/Images/listenertest.png)](./Docs/Images/listenertest.png)

### Mapping Users

[](#mapping-users)

the ConnectionWrapper contains getter and setter to match a connection with a Symfony UserInterface

```
namespace App\EventListener;

use App\Security\Authenticator;
use Snoke\Websocket\Event\RequestReceived;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: RequestReceived::class, method: 'onRequestReceived')]
final class AuthListener
{
    public function __construct(
        private readonly Authenticator,
        private readonly SerializerInterface
    ) {}

    public function onRequestReceived(RequestReceived $event): void
    {
        $request = $event->getFrame();
        $connection = $event->getConnection();
        if ($request['type'] === 'auth') {
            $payload = $request['payload'];
            $user = $this->authenticator->authenticate($payload['identifier'],$payload['password']);
            $connection->setUser($user);
            $connection->send($serializer->serialize($user, 'json'));
        }
    }
}
```

### Broadcasting

[](#broadcasting)

you can access all connections in the Listeners through the event

```
foreach($event->getConnections() as $connection) {
    $connection->send($message);
}
```

### Available Events

[](#available-events)

- ServerStarted: Triggered when the WebSocket server is started.
- ConnectionOpened: Triggered when a new WebSocket connection is established.
- ConnectionClosed: Triggered when a WebSocket connection is closed.
- Error: Triggered when an error occurs.
- MessageReceived: Triggered when a WebSocket message is received.
- TextFrame: Triggered after MessageReceived when a text message frame is received (WebSocketOpcode::TextFrame).
- BinaryFrame: Triggered after MessageReceived when a binary message frame is received (WebSocketOpcode::BinaryFrame).
- ContinuationFrame: Triggered after MessageReceived d when a continuation frame is received for a fragmented message (WebSocketOpcode::ContinuationFrame).
- ConnectionCloseFrame: Triggered after MessageReceived when a connection close frame is received (WebSocketOpcode::ConnectionCloseFrame).
- PingFrame: Triggered after DataReceived when a ping frame is received (WebSocketOpcode::PingFrame).
- PongFrame: Triggered after DataReceived when a pong frame is received (WebSocketOpcode::PongFrame).

Advanced
--------

[](#advanced)

### Message Fragmentation

[](#message-fragmentation)

#### The server handles fragmented messages using the following opcodes:

[](#the-server-handles-fragmented-messages-using-the-following-opcodes)

```
TextFrame (0x1)
BinaryFrame (0x2)
ContinuationFrame (0x0)

```

#### When a message is fragmented:

[](#when-a-message-is-fragmented)

```
The first frame (Text or Binary Frame) starts with FIN set to 0.
Subsequent frames (Continuation Frames) continue the message with FIN set to 0 until the last frame.
The last frame of the message has FIN set to 1, indicating the end of the fragmented message.

```

Ensure your application handles fragmented messages correctly based on RFC 6455 specifications.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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

4

Last Release

685d ago

### Community

Maintainers

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

---

Top Contributors

[![snoke](https://avatars.githubusercontent.com/u/17656154?v=4)](https://github.com/snoke "snoke (77 commits)")

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19562.3M1.3k](/packages/drupal-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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