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

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

joni-jones/yii2-wschat
======================

Online chat based on web sockets and ratchet php

1.0.1(9y ago)981.3k44[6 issues](https://github.com/joni-jones/yii2-wschat/issues)MITPHP

Since Dec 3Pushed 9y ago11 watchersCompare

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

READMEChangelog (7)Dependencies (14)Versions (9)Used By (0)

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

[](#web-socket-chat)

Online chat based on web sockets and ratchet php

[![Latest Stable Version](https://camo.githubusercontent.com/564465fcaf2aa6ce6acab7f64104f25eb7993b471c879e588fde7149257fe505/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6e692d6a6f6e65732f796969322d7773636861742f762f737461626c65)](https://packagist.org/packages/joni-jones/yii2-wschat)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7e4f692ea9ceb8d9469cae561017243fc402b61468c65be014ab5ff658d9f4fc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f6e692d6a6f6e65732f796969322d7773636861742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/joni-jones/yii2-wschat/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/79b4045aa97f4fa6d9b1cf33f20e78218f5ea387bbc6b9fb4bd8f08a418d7a39/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6e692d6a6f6e65732f796969322d7773636861742f646f776e6c6f616473)](https://packagist.org/packages/joni-jones/yii2-wschat)[![License](https://camo.githubusercontent.com/4fe310d7706e1a4d3a131b437c9a6dc8fd9beb18cfc7638f509958cfc3e7547b/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6e692d6a6f6e65732f796969322d7773636861742f6c6963656e7365)](https://packagist.org/packages/joni-jones/yii2-wschat)[![Join the chat at https://gitter.im/joni-jones/yii2-wschat](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/joni-jones/yii2-wschat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

!\[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 joni-jones/yii2-wschat

```

or add

```
"joni-jones/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 jones\wschat\components\Chat;
        use jones\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

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% 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 ~98 days

Recently: every ~105 days

Total

7

Last Release

3589d ago

Major Versions

0.0.7 → 1.0.0-beta2016-02-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/98dc304c67b7a16776631b1b2058be9c4dc084cc3c1986e17c03689a5bbb609a?d=identicon)[joni-jones](/maintainers/joni-jones)

---

Top Contributors

[![YevSent](https://avatars.githubusercontent.com/u/2736528?v=4)](https://github.com/YevSent "YevSent (89 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")

---

Tags

backboneratchetwebsocketsyii2yii2-extensionwebsocketyii2extensionRatchetchatbackbone

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[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)[kyrne/websocket

Integrated Pusher replacement.

121.6k1](/packages/kyrne-websocket)

PHPackages © 2026

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