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

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

neovash23/yii2-socketio
=======================

The simple and powerful socketio for the Yii2 framework

1.2.3(7y ago)01MITPHP

Since May 25Pushed 5y agoCompare

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

READMEChangelogDependencies (6)Versions (12)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/7b00dc807ca934d4d107cc0e0a837773b12fdf53376418e0cd5d8e54644e6ebd/68747470733a2f2f706f7365722e707567782e6f72672f796969636f642f796969322d736f636b6574696f2f762f737461626c65)](https://packagist.org/packages/yiicod/yii2-socketio) [![Total Downloads](https://camo.githubusercontent.com/12403c26ff6316bd03361f9d85993ca15dfe8a32b383eb32110b7713e5c22470/68747470733a2f2f706f7365722e707567782e6f72672f796969636f642f796969322d736f636b6574696f2f646f776e6c6f616473)](https://packagist.org/packages/yiicod/yii2-socketio) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/570c7692122bfa32dddfdb791a88c028a26d9c9193338c4acaba7e1b5b81d01e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969636f642f796969322d736f636b6574696f2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yiicod/yii2-socketio/?branch=master)[![Code Climate](https://camo.githubusercontent.com/df3c5d8809ee26ca190525310f89529702d4a072daabe91f443b90208ae4d18f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f796969636f642f796969322d736f636b6574696f2f6261646765732f6770612e737667)](https://codeclimate.com/github/yiicod/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/yiicod/yii2-soketio/server
    npm install
```

#### Console config (simple fork)

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

```
    'controllerMap' => [
        'socketio' => [
            'class' => \yiicod\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' => \yiicod\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' => \yiicod\socketio\EventManager::class,
            'nsp' => 'some_unique_key',
            // Namespaces with events folders
            'namespaces' => [
                'app\socketio',
            ]
        ],
        'broadcastDriver' => [
            'class' => \yiicod\socketio\drivers\RedisDriver::class,
            'hostname' => 'localhost',
            'port' => 6379,
        ],
    ]
```

##### Create publisher from server to client

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

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

    class CountEvent implements EventInterface, EventPubInterface
    {
        /**
         * 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
         * @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
    \yiicod\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10])
```

##### Create receiver from client to server

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

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

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

        /**
         * 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 yiicod\socketio\events\EventSubInterface;
    use yiicod\socketio\events\EventInterface;
    use yiicod\socketio\events\EventPolicyInterface;

    class MarkAsReadEvent implements EventInterface, EventSubInterface, EventPolicyInterface
    {
        /**
         * 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
         * @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 yiicod\socketio\events\EventPubInterface;
    use yiicod\socketio\events\EventInterface;
    use yiicod\socketio\events\EventRoomInterface;

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

        /**
         * 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
         * @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
    \yiicod\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10, 'userId' => 10])
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 74.2% 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 ~38 days

Recently: every ~29 days

Total

11

Last Release

2888d ago

### Community

Maintainers

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

---

Top Contributors

[![lexxorlov](https://avatars.githubusercontent.com/u/7910574?v=4)](https://github.com/lexxorlov "lexxorlov (23 commits)")[![orlov-alexey](https://avatars.githubusercontent.com/u/95412821?v=4)](https://github.com/orlov-alexey "orlov-alexey (5 commits)")[![neovash23](https://avatars.githubusercontent.com/u/18298986?v=4)](https://github.com/neovash23 "neovash23 (3 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[drupal/core

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

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[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)[contao/core-bundle

Contao Open Source CMS

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

PHPackages © 2026

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