PHP code example of joni-jones / yii2-wschat

1. Go to this page and download the library: Download joni-jones/yii2-wschat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joni-jones / yii2-wschat example snippets


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

        ServerController extends \yii\console\Controller
        

        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();
            }
        }
        

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

        yii server/run
        

     echo ChatWidget::widget();
  
     echo ChatWidget::widget([
        'auth' => true,
        'user_id' => '' // setup id of current logged user
    ]);

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