PHPackages                             sfcod/socketio - 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. sfcod/socketio

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

sfcod/socketio
==============

SocketIo adapter for Symfony

1.4.0(3y ago)252.7k↓75%8[1 PRs](https://github.com/sfcod/socketio/pulls)MITPHPPHP ^7.4

Since Feb 21Pushed 1y ago3 watchersCompare

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

READMEChangelog (4)Dependencies (8)Versions (23)Used By (0)

Symfony Socket.io bundle
========================

[](#symfony-socketio-bundle)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bb6cb68feb387853856cc19fd3fc4efe4e9cd73d8d5e3ed6291fa58619eedd95/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7366636f642f736f636b6574696f2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sfcod/socketio/?branch=master)[![Code Climate](https://camo.githubusercontent.com/6b9cf0abd52424fe52577742f167c94e3ef635e6aa7fdd481a8ba54aaa525d05/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f7366636f642f736f636b6574696f2f6261646765732f6770612e737667)](https://codeclimate.com/github/sfcod/socketio)

Use all power of socket.io in your Symfony project.

#### Config

[](#config)

###### Install node, after install npm

[](#install-node-after-install-npm)

```
    npm install --prefix ./vendor/sfcod/socketio/Server
```

```
services:
    App\SocketIo\:
        resource: '../src/SocketIo/*'
        tags: ['sfcod.socketio.event']
        # If you want override default JoinHandler/LeaveHandler. For example, add some condition for join/leave a room.
        exclude:
            - '../src/SocketIo/JoinHandler.php' # Optional
            - '../src/SocketIo/LeaveHandler.php' # Optional

    # If you want override default JoinHandler
    SfCod\SocketIoBundle\Service\JoinHandler:
        class: App\SocketIo\JoinHandler
        tags: ['sfcod.socketio.event']

    # If you want override default LeaveHandler
    SfCod\SocketIoBundle\Service\LeaveHandler:
        class: App\SocketIo\LeaveHandler
        tags: ['sfcod.socketio.event']
```

Extend base class or use SF decorator. Ovveride fire or handle methods if it needs.

```
namespace App\SocketIo;

use SfCod\SocketIoBundle\Service\JoinHandler as JoinHandlerBase;

class JoinHandler extends JoinHandlerBase
{
    public function fire(): array
    {
        // Some additional logic here.
        // ...
        return array_merge_recursive(parent::fire(), [
            'key' => 'value'
        ]);
    }
}
```

###### Process Middlewares

[](#process-middlewares)

If you use doctrine, then you can connect "doctrine reconnect", then it will be reconnect for each process.

```
sfcod_socketio:
    processMiddlewares:
        - 'SfCod\SocketIoBundle\Middleware\Process\DoctrineReconnect'
```

```
###> socketio config ###
SOCKET_IO_WS_SERVER=localhost:1358
SOCKET_IO_WS_CLIENT=localhost:1358
SOCKET_IO_SSL='' || '{"key":"path to key", "cert":"path to cert"}'
SOCKET_IO_NSP=redis
###< socketio config ###
```

JWT token auth. Put SOCKET\_IO\_AUTH\_TOKEN\_PATH OR SOCKET\_IO\_AUTH\_TOKEN\_VALUE

```
#Public jwt token key path (Will be join with base path)
SOCKET_IO_AUTH_TOKEN_PATH='/config/jwt/public.pem'
#Public key value
SOCKET_IO_AUTH_TOKEN_VALUE='public key value'
#You can change token name. Default name is 'token'
SOCKET_IO_AUTH_TOKEN_NAME='token'
```

```
    var socket = io('{your_host_address}:1367/notifications',  {
        query: {
            token: 'yourTokenHere',
        },
     });
```

#### Usage

[](#usage)

###### Start nodejs server

[](#start-nodejs-server)

```
    php bin/console socket-io:node-js-server
```

###### Start php server

[](#start-php-server)

```
    php bin/console socket-io:php-server
```

###### Create publisher from server to client

[](#create-publisher-from-server-to-client)

```
    use SfCod\SocketIoBundle\Events\EventInterface;
    use SfCod\SocketIoBundle\Events\EventPublisherInterface;
    use SfCod\SocketIoBundle\Events\AbstractEvent;

    class CountEvent extends AbstractEvent implements EventInterface, EventPublisherInterface
    {
        /**
         * Changel name. For client side this is nsp.
         */
        public static function broadcastOn(): array
        {
            return ['notifications'];
        }

        /**
         * Event name
         */
        public static function name(): string
        {
            return 'update_notification_count';
        }

        /**
         * Emit client event
         * @return array
         */
        public function fire(): array
        {
            return [
                'count' => 10,
            ];
        }
    }
```

```
    var socket = io('{your_host_address}:1367/notifications');
    socket.on('update_notification_count', function(data){
        console.log(data)
    });
```

###### Create receiver from client to server

[](#create-receiver-from-client-to-server)

```
    use SfCod\SocketIoBundle\Events\EventInterface;
    use SfCod\SocketIoBundle\Events\EventSubscriberInterface;
    use SfCod\SocketIoBundle\Events\AbstractEvent;
    use SfCod\SocketIoBundle\Service\Broadcast;

    class MarkAsReadEvent extends AbstractEvent implements EventInterface, EventSubscriberInterface
    {

        private $broadcast;

        public function __construct(Broadcast $broadcast)
        {
            $this->broadcast = $broadcast;
        }

        /**
         * Changel name. For client side this is nsp.
         */
        public static function broadcastOn(): array
        {
            return ['notifications'];
        }

        /**
         * Event name
         */
        public static function name(): string
        {
            return 'mark_as_read_notification';
        }

        /**
         * Handle client event
         */
        public function handle()
        {
            // Mark notification as read
            // And call client update
            $this->broadcast->emit('update_notification_count', ['some key' => 'some value']);
        }
    }
```

```
    var socket = io('{your_host_address}:1367/notifications');
    socket.emit('mark_as_read_notification', {id: 10});
```

You can have publisher and receiver in one event. If you need check data from client to server you should use:

- EventPolicyInterface

###### Receiver with checking from client to server

[](#receiver-with-checking-from-client-to-server)

```
    use SfCod\SocketIoBundle\Events\EventSubscriberInterface;
    use SfCod\SocketIoBundle\Events\EventInterface;
    use SfCod\SocketIoBundle\Events\EventPolicyInterface;
    use SfCod\SocketIoBundle\Events\AbstractEvent;
    use SfCod\SocketIoBundle\Service\Broadcast;

    class MarkAsReadEvent extends AbstractEvent implements EventInterface, EventSubscriberInterface, EventPolicyInterface
    {

        private $broadcast;

        public function __construct(Broadcast $broadcast)
        {
            $this->broadcast = $broadcast;
        }

        /**
         * Changel name. For client side this is nsp.
         */
        public static function broadcastOn(): array
        {
            return ['notifications'];
        }

        /**
         * Event name
         */
        public static function name(): string
        {
            return 'mark_as_read_notification';
        }

        public function can($data): bool
        {
            // Check data from client
            return true;
        }

        /**
         * Emit client event
         * @return array
         */
        public function handle()
        {
            // Mark notification as read
            // And call client update
            $this->broadcast->emit('update_notification_count', ['some key' => 'some value']);
        }
    }
```

Socket.io rooms
---------------

[](#socketio-rooms)

- EventRoomInterface (Backend side)

```
    use SfCod\SocketIoBundle\Events\EventPublisherInterface;
    use SfCod\SocketIoBundle\Events\EventInterface;
    use SfCod\SocketIoBundle\Events\EventRoomInterface;
    use SfCod\SocketIoBundle\Events\AbstractEvent;

    class CountEvent extends AbstractEvent implements EventInterface, EventPublisherInterface, EventRoomInterface
    {
        /**
         * Changel name. For client side this is nsp.
         */
        public static function broadcastOn(): array
        {
            return ['notifications'];
        }

        /**
         * Event name
         */
        public static function name(): string
        {
            return 'update_notification_count';
        }

        /**
         * Socket.io room
         * @return string
         */
        public function room(): string
        {
            return 'user_id_' . $this->userId;
        }

        /**
         * Emit client event
         * @return array
         */
        public function fire(): array
        {
            return [
                'count' => 10,
            ];
        }
    }
```

Client side

```
    var socket = io('{your_host_address}:1367/notifications');
    socket.emit('join', {room: 'user_id_10'});
    // Now you will receive data from 'room-1'
    socket.on('update_notification_count', function(data){
        console.log(data)
    });
    // You can leave room
    socket.emit('leave', {room: 'user_id_10'});
```

Run this on the backend side

```
$this->broadcast->emit('update_notification_count', ['some key' => 'some value', 'userId' => 10]);
```

###### Default events:

[](#default-events)

- connection
- disconnect
- join
- leave

```
    use SfCod\SocketIoBundle\Events\EventSubscriberInterface;
    use SfCod\SocketIoBundle\Events\EventInterface;
    use Psr\Log\LoggerInterface;
    use SfCod\SocketIoBundle\Events\AbstractEvent;

    class СonnectionEvent extends AbstractEvent implements EventInterface, EventSubscriberInterface
    {

        private $logger;

        public function __construct(LoggerInterface $logger)
        {
            $this->logger = $logger;
        }

        /**
         * Changel name. For client side this is nsp.
         */
        public static function broadcastOn(): array
        {
            return ['notifications'];
        }

        /**
         * Event name
         */
        public static function name(): string
        {
            return 'connection'; // or 'disconnect'
        }

        /**
         * Handle client event
         */
        public function handle()
        {
            // Socket.io ID
            // $this->socketId
            $this->logger->info('disconnect', $this->payload);
        }
    }
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 67.4% 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 ~88 days

Recently: every ~242 days

Total

21

Last Release

1249d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.4.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/7934283ca98b7f31bb5bf13119a8495cad80ac9097125a48792f47caddb588b9?d=identicon)[lexxorlov](/maintainers/lexxorlov)

---

Top Contributors

[![lexxorlov](https://avatars.githubusercontent.com/u/7910574?v=4)](https://github.com/lexxorlov "lexxorlov (29 commits)")[![Mark1Z](https://avatars.githubusercontent.com/u/9988709?v=4)](https://github.com/Mark1Z "Mark1Z (12 commits)")[![denis-zf](https://avatars.githubusercontent.com/u/90699783?v=4)](https://github.com/denis-zf "denis-zf (2 commits)")

---

Tags

asybundlephpsocketsocket-iosymfonysymfony-bundlesymfony-socket-io

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/sfcod-socketio/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

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

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/manager-bundle

Provides the Contao Managed Edition

181.3M61](/packages/contao-manager-bundle)

PHPackages © 2026

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