PHPackages                             bscheshirwork/yii2-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. [Framework](/categories/framework)
4. /
5. bscheshirwork/yii2-socketio

ActiveYii2-extension[Framework](/categories/framework)

bscheshirwork/yii2-socketio
===========================

The simple and powerful socketio for the Yii2 framework

1.2.3.6(2y ago)033MITPHPPHP ~8.3.0

Since May 25Pushed 2y agoCompare

[ Source](https://github.com/bscheshirwork/yii2-socketio)[ Packagist](https://packagist.org/packages/bscheshirwork/yii2-socketio)[ RSS](/packages/bscheshirwork-yii2-socketio/feed)WikiDiscussions master Synced today

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

Socket.io Yii extension
=======================

[](#socketio-yii-extension)

Use all power of socket.io in your Yii 2 project.

[![Latest Stable Version](https://camo.githubusercontent.com/35e0288a0d9cece5b21ce9c168eacf1d5c9a01cc4e0aabe6881e40956cf7b081/68747470733a2f2f706f7365722e707567782e6f72672f627363686573686972776f726b2f796969322d736f636b6574696f2f762f737461626c65)](https://packagist.org/packages/bscheshirwork/yii2-socketio) [![Total Downloads](https://camo.githubusercontent.com/e42f76a3b5e5dc72fbf0314bb36a6de5e5907f4d9da36ac54db98d5633892565/68747470733a2f2f706f7365722e707567782e6f72672f627363686573686972776f726b2f796969322d736f636b6574696f2f646f776e6c6f616473)](https://packagist.org/packages/bscheshirwork/yii2-socketio) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/9ab283e57c53a66cf9eecedb992a101f35a13cefb6bb2cf8bae33c14d160306c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f627363686573686972776f726b2f796969322d736f636b6574696f2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bscheshirwork/yii2-socketio/?branch=master)[![Code Climate](https://camo.githubusercontent.com/64eafc6580145bbce0b0cb01c20a79fa2a070428667854592eefcec315e90603/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f627363686573686972776f726b2f796969322d736f636b6574696f2f6261646765732f6770612e737667)](https://codeclimate.com/github/bscheshirwork/yii2-socketio)

Config
------

[](#config)

##### Install node + additional npm

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

```
    cd ~
    curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
    sudo bash nodesource_setup.sh
    cd vendor/bscheshirwork/yii2-socketio/server
    npm install
```

#### Console config (simple fork)

[](#console-config-simple-fork)

```
    'controllerMap' => [
        'socketio' => [
            'class' => \bscheshirwork\socketio\commands\SocketIoCommand::class,
            'server' => 'localhost:1367'
        ],
    ]
```

###### Start sockeio server

[](#start-sockeio-server)

```
    php yii socketio/start
```

###### Stop sockeio server

[](#stop-sockeio-server)

```
    php yii socketio/stop
```

#### Console config + PM2(). This variant more preferable for console configuration

[](#console-config--pm2httppm2keymetricsio-this-variant-more-preferable-for-console-configuration)

```
    'controllerMap' => [
        'socketio' => [
            'class' => \bscheshirwork\socketio\commands\WorkerCommand::class,
            'server' => 'localhost:1367'
        ],
    ]
```

###### pm2 config:

[](#pm2-config)

```
    {
      "apps": [
        {
          "name": "socket-io-node-js-server",
          "script": "yii",
          "args": [
            "socketio/node-js-server"
          ],
          "exec_interpreter": "php",
          "exec_mode": "fork_mode",
          "max_memory_restart": "1G",
          "watch": false,
          "merge_logs": true,
          "out_file": "runtime/logs/node_js_server_out.log",
          "error_file": "runtime/logs/node_js_server_err.log"
        },
        {
          "name": "socket-io-php-server",
          "script": "yii",
          "args": [
            "socketio/php-server"
          ],
          "exec_interpreter": "php",
          "exec_mode": "fork_mode",
          "max_memory_restart": "1G",
          "watch": false,
          "merge_logs": true,
          "out_file": "runtime/logs/php_server_out.log",
          "error_file": "runtime/logs/php_server_err.log"
        },
      ]
    }
```

###### Run PM2 daemons

[](#run-pm2-daemons)

```
pm2 start daemons-app.json
```

###### PM2 will be run these two commands in background::

[](#pm2-will-be-run-these-two-commands-in-background)

```
    php yii socketio/node-js-server
    php yii socketio/php-server
```

##### Common config

[](#common-config)

```
    'components' =>[
        'broadcastEvents' => [
            'class' => \bscheshirwork\socketio\EventManager::class,
            'nsp' => 'some_unique_key',
            // Namespaces with events folders
            'namespaces' => [
                'app\socketio',
            ]
        ],
        'broadcastDriver' => [
            'class' => \bscheshirwork\socketio\drivers\RedisDriver::class,
            'hostname' => 'localhost',
            'port' => 6379,
        ],
    ]
```

##### Create publisher from server to client

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

```
    use bscheshirwork\socketio\events\EventInterface;
    use bscheshirwork\socketio\events\EventPubInterface;

    class CountEvent implements EventInterface, EventPubInterface
    {
        /**
         * Channel 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
         * @param array $data
         * @return array
         */
        public function fire(array $data): array
        {
            return $data;
        }
    }
```

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

```
    //Run broadcast to client
    \bscheshirwork\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10])
```

##### Create receiver from client to server

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

```
    use bscheshirwork\socketio\events\EventInterface;
    use bscheshirwork\socketio\events\EventSubInterface;

    class MarkAsReadEvent implements EventInterface, EventSubInterface
    {
        /**
         * Channel 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';
        }

        /**
         * Emit client event
         * @param array $data
         * @return array
         */
        public function handle(array $data)
        {
            // Mark notification as read
            // And call client update
            // Broadcast::emit('update_notification_count', ['some_key' => 'some_value']);

            // Push some log
            file_put_contents(\Yii::getAlias('@app/../file.txt'), serialize($data));
        }
    }
```

```
    var socket = io('localhost: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 bscheshirwork\socketio\events\EventSubInterface;
    use bscheshirwork\socketio\events\EventInterface;
    use bscheshirwork\socketio\events\EventPolicyInterface;

    class MarkAsReadEvent implements EventInterface, EventSubInterface, EventPolicyInterface
    {
        /**
         * Channel 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
         * @param array $data
         * @return array
         */
        public function handle(array $data)
        {
            // Mark notification as read
            // And call client update
            Broadcast::emit('update_notification_count', ['some_key' => 'some_value']);
        }
    }
```

Soket.io has room functionl. If you need it, you should implement:

- EventRoomInterface

```
    use bscheshirwork\socketio\events\EventPubInterface;
    use bscheshirwork\socketio\events\EventInterface;
    use bscheshirwork\socketio\events\EventRoomInterface;

    class CountEvent implements EventInterface, EventPubInterface, EventRoomInterface
    {
        /**
         * User id
         * @var int
         */
        protected $userId;

        /**
         * Channel 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
         * @param array $data
         * @return array
         */
        public function fire(array $data): array
        {
            $this->userId = $data['userId'];
            return [
                'count' => 10,
            ];
        }
    }
```

```
    var socket = io('localhost:1367/notifications');
    socket.emit('join', {room: 'user_id_'});
    // 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');
```

```
    //Run broadcast to user id = 10
    \bscheshirwork\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10, 'userId' => 10])
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~152 days

Recently: every ~8 days

Total

17

Last Release

890d ago

### Community

Maintainers

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

---

Top Contributors

[![lexxorlov](https://avatars.githubusercontent.com/u/7910574?v=4)](https://github.com/lexxorlov "lexxorlov (25 commits)")[![bscheshirwork](https://avatars.githubusercontent.com/u/5769211?v=4)](https://github.com/bscheshirwork "bscheshirwork (19 commits)")[![orlov-alexey](https://avatars.githubusercontent.com/u/95412821?v=4)](https://github.com/orlov-alexey "orlov-alexey (5 commits)")[![Julielesss](https://avatars.githubusercontent.com/u/36435376?v=4)](https://github.com/Julielesss "Julielesss (3 commits)")[![christopherwulff](https://avatars.githubusercontent.com/u/16084962?v=4)](https://github.com/christopherwulff "christopherwulff (1 commits)")

###  Code Quality

Static AnalysisRector

Code StyleECS

### Embed Badge

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

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

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M302](/packages/laravel-horizon)[oro/platform

Business Application Platform (BAP)

645143.5k115](/packages/oro-platform)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[drupal/core

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

21866.0M1.7k](/packages/drupal-core)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[lion/bundle

Lion-framework configuration and initialization package

122.3k4](/packages/lion-bundle)

PHPackages © 2026

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