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

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

hyperia/yii2-socketio
=====================

The simple and powerful socketio for the Yii2 framework

1.3.2(1y ago)11.1k↓50%2MITPHP

Since May 25Pushed 1y agoCompare

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

READMEChangelog (3)Dependencies (6)Versions (19)Used By (0)

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

[](#socketio-yii-extension)

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

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/hyperia/yii2-soketio/server
    npm install
```

#### Console config (simple fork)

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

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

##### Create publisher from server to client

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

```
    use hyperia\socketio\events\EventInterface;
    use hyperia\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
    \hyperia\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10])
```

##### Create receiver from client to server

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

```
    use hyperia\socketio\events\EventInterface;
    use hyperia\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 hyperia\socketio\events\EventSubInterface;
    use hyperia\socketio\events\EventInterface;
    use hyperia\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 hyperia\socketio\events\EventPubInterface;
    use hyperia\socketio\events\EventInterface;
    use hyperia\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
    \hyperia\socketio\Broadcast::emit(CountEvent::name(), ['count' => 10, 'userId' => 10])
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 69.7% 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 ~196 days

Recently: every ~560 days

Total

14

Last Release

725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9861d8483a334bd54621b1829f2b55620417df08080a0fe29426659eacb9385b?d=identicon)[karster](/maintainers/karster)

---

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)")[![janki1](https://avatars.githubusercontent.com/u/2636233?v=4)](https://github.com/janki1 "janki1 (3 commits)")[![jurajkalafut](https://avatars.githubusercontent.com/u/16917831?v=4)](https://github.com/jurajkalafut "jurajkalafut (2 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[civicrm/civicrm-core

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

728272.9k20](/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)

PHPackages © 2026

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