PHPackages                             geloft/yii2-websocket - 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. [Framework](/categories/framework)
4. /
5. geloft/yii2-websocket

ActiveYii2-extension[Framework](/categories/framework)

geloft/yii2-websocket
=====================

Yii2 websocket server component

012PHP

Since Oct 2Pushed 1y agoCompare

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

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

Yii2 [WebSocketServer](/WebSocketServer.php)
============================================

[](#yii2-websocketserver)

[![Latest Stable Version](https://camo.githubusercontent.com/7917964099e48a0643e2fa18c977f715441e60ba1cf3cf7cc5ec118c84ced14a/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d776562736f636b65742f762f737461626c65)](https://packagist.org/packages/consik/yii2-websocket)[![Total Downloads](https://camo.githubusercontent.com/afccade01c8a4efd3f5d8c5480b6bcf5ef422ae41d96ad638a486ee33d512003/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d776562736f636b65742f646f776e6c6f616473)](https://packagist.org/packages/consik/yii2-websocket)[![License](https://camo.githubusercontent.com/6403035d65706063c17028c39146e4cc99fb490b246b30ffa961110e6d3c6086/68747470733a2f2f706f7365722e707567782e6f72672f636f6e73696b2f796969322d776562736f636b65742f6c6963656e7365)](https://packagist.org/packages/consik/yii2-websocket)

Used [Ratchet](http://socketo.me/)

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

[](#installation)

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

Either run

```
composer require consik/yii2-websocket

```

or add

```
"consik/yii2-websocket": "^1.0"
```

WebSocketServer class description
---------------------------------

[](#websocketserver-class-description)

### Properties

[](#properties)

1. ` int $port = 8080` - Port number for websocket server
2. ` bool $closeConnectionOnError = true` - Close connection or not when error occurs with it
3. ` bool $runClientCommands = true` - Check client's messages for commands or not
4. ` null|IoServer $server = null` - IOServer object
5. ` null|\SplObjectStorage $clients = null` - Storage of connected clients

### Methods

[](#methods)

### Events

[](#events)

- EVENT\_WEBSOCKET\_OPEN

> **Class** yii\\base\\Event - Triggered when binding is successfully completed

- EVENT\_WEBSOCKET\_CLOSE

> **Class** yii\\base\\Event - Triggered when socket listening is closed

- EVENT\_WEBSOCKET\_OPEN\_ERROR

> **Class** [events\\ExceptionEvent](/events/ExceptionEvent.php) - Triggered when throwed Exception on binding socket

- EVENT\_CLIENT\_CONNECTED

> **Class** [events\\WSClientEvent](/events/WSClientEvent.php) - Triggered when client connected to the server

- EVENT\_CLIENT\_DISCONNECTED

> **Class** [events\\WSClientEvent](/events/WSClientEvent.php) - Triggered when client close connection with server

- EVENT\_CLIENT\_ERROR

> **Class** [events\\WSClientErrorEvent](/events/WSClientErrorEvent.php) - Triggered when an error occurs on a Connection

- EVENT\_CLIENT\_MESSAGE

> **Class** [events\\WSClientMessageEvent](/events/WSClientMessageEvent.php) - Triggered when message recieved from client

- EVENT\_CLIENT\_RUN\_COMMAND

> **Class** [events\\WSClientCommandEvent](/events/WSClientCommandEvent.php) - Triggered when controller starts user's command

- EVENT\_CLIENT\_END\_COMMAND

> **Class** [events\\WSClientCommandEvent](/events/WSClientCommandEvent.php) - Triggered when controller finished user's command

Examples
--------

[](#examples)

### Simple echo server

[](#simple-echo-server)

Create your server class based on WebSocketServer. For example `daemons\EchoServer.php`:

```
