PHPackages                             ratacibernetica/yii2-node-socket - 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. ratacibernetica/yii2-node-socket

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ratacibernetica/yii2-node-socket
================================

This is a fork of oncesk/yii-node-socket

v1.0(10y ago)54614[5 issues](https://github.com/ratacibernetica/yii2-node-socket/issues)PHP

Since Oct 2Pushed 9y ago5 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

\####Disclaimer This fork is under development to make it work with Yii2. As of now, i haven't checked the subscription feature, Many parts of code have been rewritten and tested only in a project, so i guess this doesn't work *not out of the box* .

Be warned.

Yii2 Node Socket
================

[](#yii2-node-socket)

Connect php, javascript, nodejs in one Yii application.

\####Yii1

Hi, if you need work with yii1 you can do it from ()

\####What you can do:

- send event(s) to all clients or in concrete room or in concrete channel
- now you can send events to single (concrete user) by user id!
- call some function or object method in window context
- you can change DOM model with jquery from php
- ability to set up data and get it in your javascript application
- send events from javascript for all clients or clients -in concrete room or channel-

\##Changes

- Updated for Yii 2.0
- Added Namespacing Updated for Yii 2.0
- Commposer settings updated to work with yii extension updates

\##Requirements

- linux/unix/windows
- git
- vps or dedicated server (for nodejs process)
- curl has to be installed or enabled

\#Installation

Install nodejs, if not installed see
Install extension

- Composer

```
composer require ratacibernetica/yii2-node-socket
```

- Using git clone

```
$> git clone https://github.com/ratacibernetica/yii2-node-socket.git
```

Now go to the folder where you install extension ***vendors/ratacibernetica/yii2-node-socket*** and execute

```
$> git submodule init
$> git submodule update
```

Yii2 configuration

- Configure console command in (***console/config/main.php***). You can use config below:

```
	...
	'controllerMap' => [
		'node-socket' => '\YiiNodeSocket\NodeSocketCommand',
	],
	...
	'components' => [
		'nodeSocket' => [
		    'class' => '\YiiNodeSocket\NodeSocket',
		    'host' => 'localhost',
		    'allowedServerAddresses' => [
		        "localhost",
		        "127.0.0.1"
		    ],
		],
	],
```

- Register Yii component, need to add into **frontend/config/main.php in your frontend application**:

```
		'nodeSocket' => [
		    'class' => '\YiiNodeSocket\NodeSocket',
		    'dbOptions' => '',
		    'host' => 'localhost',
		    'allowedServerAddresses' => [
		        "localhost",
		        "127.0.0.1"
		    ],
		    'origin' => '*:*',
		    'sessionVarName' => 'PHPSESSID',
		    'port' => 3001,
		    'socketLogFile' => '/var/log/node-socket.log',
		],
```

> Notice: ***host*** should be a domain name like in you virtual host configuration or server ip address if you request page using ip address

- Configure aliases in the common config in (***common/config/main.php***).
- The first is for Yii to find the PHP Namespace and the second is to find the JS assets.
- You can use config below:

```
    'aliases' => [
        '@YiiNodeSocket' => '@vendor/ratacibernetica/yii2-node-socket/lib/php',
        '@nodeWeb' => '@vendor/ratacibernetica/yii2-node-socket/lib/js',
        '@console'=>dirname(dirname(__DIR__)) . '/console',
    ],
```

> Notice: if you will be using ***behaviors*** or node-socket models, you need to add nodeSocket component in ***preload*** components list

```
    'bootstrap' => ['log', 'nodeSocket'],
```

Install ***nodejs*** components in ***application.ext.yii-node-socket.lib.js.server***:

```
$> npm install
```

Congratulation, installation completed!

> Notice: if the name of the component will not be **nodeSocket**, your need to use special key in console command --componentName=component\_name

> Notice: It's highly probable that the JS don't load by itself, so we must register the YiiSocketNode Assets in the view/layout.

```
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use kartik\form\ActiveForm;
use frontend\assets\AppAsset;
use kartik\widgets\AlertBlock;

/* @var $this \yii\web\View */
/* @var $content string */

\YiiNodeSocket\Assets\NodeSocketAssets::register($this);
AppAsset::register($this);
?>
