PHPackages                             fbalabanov/yii2-wschat - 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. fbalabanov/yii2-wschat

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

fbalabanov/yii2-wschat
======================

Online chat based on web sockets and ratchet php

v1.0(8y ago)013MITPHP

Since Oct 21Pushed 8y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

Web Socket Chat
===============

[](#web-socket-chat)

Online chat based on web sockets and ratchet php

!\[Demo\] (doc/demo.gif)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist fbalabanov/yii2-wschat

```

or add

```
"fbalabanov/yii2-wschat": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

1. The chat extension can use any database storage supported by yii.

    If `mongodb` extension specified the chat will be try to use it as message history storage, otherwise extension will be use specified in application config db component.

    The simple example how to use mongodb storage is listed below. Install [MongoDB](http://docs.mongodb.org/) and [yii2-mongodb](http://www.yiiframework.com/doc-2.0/ext-mongodb-index.html)extension to store messages history and you need just specify connection in `console` config:

    ```
    'components' => [
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://username:password@localhost:27017/dbname'
        ]
    ]
    ```

    In created mongodb database you need to create collection named as `history`;

    IMPORTANT: if you use db component - you need to create table `history` in your database. The simple examples postgresql and mysql you can see in `tests/codeception` directory.
2. To start chat server need to create console command and setup it as demon:

    - Create controller which extends `yii\console\Controller`:

        ```
        ServerController extends \yii\console\Controller
        ```
    - Create action to start server:

        ```
        namespace app\commands;

        use fbalabanov\wschat\components\Chat;
        use fbalabanov\wschat\components\ChatManager;
        use Ratchet\Server\IoServer;
        use Ratchet\Http\HttpServer;
        use Ratchet\WebSocket\WsServer;

        class ServerController extends \yii\console\Controller
        {
            public function actionRun()
            {
                $server = IoServer::factory(new HttpServer(new WsServer(new Chat(new ChatManager()))), 8080);
                $server->run();
            }
        }
        ```

    If you want to use chat for auth users, you must to specify `userClassName` property for `ChatManager` instance. For example:

    ```
        $manager = Yii::configure(new ChatManager(), [
            'userClassName' => '\yii\db\ActiveRecord' //allow to get users from MySQL or PostgreSQL
        ]);
    ```

    - Now, you can run chat server with `yii` console command:

        ```
        yii server/run
        ```
3. To add chat on page just call:

    ```

    ```

    or if you want to use chat for auth users just add config as parameter:

    ```

    ```

    ```
     List of available options:
     auth - boolean, default: false
     user_id - mixed, default: null
     port - integer, default: 8080
     chatList - array (allow to set list of preloaded chats), default: [
         id => 1,
         title => 'All'
     ],
     add_room - boolean, default: true (allow to user create new chat rooms)

    ```

You can also store added chat, just specify js callback for vent events:

```
Chat.vent('chat:add', function(chatModel) {
    console.log(chatModel);
});

```

This code snipped may be added in your code, but after chat widget loading. In the callback you will get access to `Chat.Models.ChatRoom` backbone model. Now, you need add your code to save chat room instead `console.log()`.

> If `YII_DEBUG` is enabled - all js scripts will be loaded separately.

Also by default chat will try to load two images: `/avatar_16.png` and `/avatar_32.png` from assets folder.

Possible issues
---------------

[](#possible-issues)

If you don't see any messages in console log, check `flushInterval` and `exportInterval` of your log configuration component. The simple configuration may looks like this:

```
'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
    'flushInterval' => 1,
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['error', 'warning', 'info'],
            'logVars' => [],
            'exportInterval' => 1
        ],
    ],
],
```

If you use `https` protocol chat will try to connect to `wss` instead `ws`. But Ratchet PHP [does not support](https://github.com/reactphp/react/issues/2) work via SSL, so you need to use some proxy like [stunnel](https://www.stunnel.org/index.html).

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b8f6875e5c6775c84be009d6d22d88680720f1f64c8c35230b8935a18c85831?d=identicon)[fbalabanov](/maintainers/fbalabanov)

---

Top Contributors

[![fbalabanov](https://avatars.githubusercontent.com/u/17606499?v=4)](https://github.com/fbalabanov "fbalabanov (2 commits)")

---

Tags

websocketyii2extensionRatchetchatbackbone

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/fbalabanov-yii2-wschat/health.svg)

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

###  Alternatives

[joni-jones/yii2-wschat

Online chat based on web sockets and ratchet php

981.3k](/packages/joni-jones-yii2-wschat)[consik/yii2-websocket

Yii2 websocket server component

9275.9k2](/packages/consik-yii2-websocket)[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.5M20](/packages/linslin-yii2-curl)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[immusen/yii2-swoole-websocket

Websocket server for Yii2 base on swoole 4, Support JSONRPC, Resolve 'method' as a route reflect into controller/action, And support http or redis pub/sub to trigger async task from your web application.

338.8k](/packages/immusen-yii2-swoole-websocket)[yiiplus/yii2-websocket

使用yii2封装 websocket 扩展

212.6k](/packages/yiiplus-yii2-websocket)

PHPackages © 2026

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