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

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

arkotik/yii2-socketio
=====================

The simple and powerful socketio for the Yii2 framework

1.2.5.1(6y ago)017MITPHP

Since May 25Pushed 6y agoCompare

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

READMEChangelog (3)Dependencies (6)Versions (16)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

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 57.5% 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 ~65 days

Recently: every ~134 days

Total

14

Last Release

2425d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k17](/packages/civicrm-civicrm-core)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[overtrue/php-opencc

中文简繁转换，支持词汇级别的转换、异体字转换和地区习惯用词转换（中国大陆、台湾、香港、日本新字体）。基于 \[BYVoid/OpenCC\](https://github.com/BYVoid/OpenCC) 数据实现。

12130.7k](/packages/overtrue-php-opencc)[yiicod/yii2-socketio

The simple and powerful socketio for the Yii2 framework

4619.7k](/packages/yiicod-yii2-socketio)

PHPackages © 2026

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