PHPackages                             dkhru/yii2-socket-events - 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. dkhru/yii2-socket-events

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

dkhru/yii2-socket-events
========================

Best way to update content on client from server

6381[1 issues](https://github.com/dkhru/yii2-socket-events/issues)PHP

Since Apr 20Pushed 10y ago3 watchersCompare

[ Source](https://github.com/dkhru/yii2-socket-events)[ Packagist](https://packagist.org/packages/dkhru/yii2-socket-events)[ RSS](/packages/dkhru-yii2-socket-events/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

yii2-socket-event
=================

[](#yii2-socket-event)

Best way to send data to client other websocket on yii2 application

Author
------

[](#author)

Dmitriy Khristianov (dkh)

Require
-------

[](#require)

yii2, npm, node, redis

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist dkhru/yii2-socket-events "*"

```

or add

```
"dkhru/yii2-socket-events": "*"

```

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

Configure and run rtserver
--------------------------

[](#configure-and-run-rtserver)

Once the extension is installed, `cd vendor/dkhru/nodejs` and install node modules `npm install console-stamp express redis socket.io`Generate SSL certificates for rtserver. Copy `config.js.example` to `config.js`

For testing simple run in console `node rtserver.js`On linux server use init script example in `rtserver.initd`

Usage
-----

[](#usage)

In yii2 configure SocketEvent component

```
...
'components'=>[
...
'se'=>[
            'class'=>\dkhru\socketEvents\SE::className(),
            'socketUrl'=>https://127.0.0.1:8089,
         ],
...
]
...

```

Now, you can create you server driven widgets from `RegisterSEWidget`

Simple example:

```
...
class RestWidget extends RegisterSEWidget
{
      public $rest;
      public function init()
      {
         if( \Yii::$app->user->isGuest )
            throw new ForbiddenHttpException();
         $this->object='user';
         $this->id=\Yii::$app->user->id;
         $restJs=
