PHPackages                             scherersoftware/cake-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. scherersoftware/cake-websocket

ActiveCakephp-plugin[Framework](/categories/framework)

scherersoftware/cake-websocket
==============================

Websocket plugin for CakePHP

v2.1.0(3y ago)2319.5k↓50%7[3 issues](https://github.com/scherersoftware/cake-websocket/issues)MITPHPPHP &gt;=7.3.0

Since Jan 26Pushed 10mo ago3 watchersCompare

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

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

[![CakePHP 3 Websocket  Plugin](https://raw.githubusercontent.com/scherersoftware/cake-websocket/master/websocket.png)](https://raw.githubusercontent.com/scherersoftware/cake-websocket/master/websocket.png)

[![License](https://camo.githubusercontent.com/fbe0c736dc7979794449aaa5fde9f0f567c16a4b941c4f6794f08a1f44c6e93b/68747470733a2f2f706f7365722e707567782e6f72672f73636865726572736f6674776172652f63616b652d776562736f636b65742f6c6963656e7365)](https://packagist.org/packages/scherersoftware/cake-websocket)[![Latest Stable Version](https://camo.githubusercontent.com/25a9862a738fa528134e97a43f72de6ffb54593ee50399104767aaedf61575df/68747470733a2f2f706f7365722e707567782e6f72672f73636865726572736f6674776172652f63616b652d776562736f636b65742f762f737461626c65)](https://packagist.org/packages/scherersoftware/cake-websocket)[![Latest Unstable Version](https://camo.githubusercontent.com/4febafcf915c4e1fb30c87098c01ed27a96771cf9b5c9425132fd7c06316fd1a/68747470733a2f2f706f7365722e707567782e6f72672f73636865726572736f6674776172652f63616b652d776562736f636b65742f762f756e737461626c65)](https://packagist.org/packages/scherersoftware/cake-websocket)[![Monthly Downloads](https://camo.githubusercontent.com/a5b43a15c42898a8e9074fe4974bd4cf8b69c71228bca851f452a776a05a98c3/68747470733a2f2f706f7365722e707567782e6f72672f73636865726572736f6674776172652f63616b652d776562736f636b65742f642f6d6f6e74686c79)](https://packagist.org/packages/scherersoftware/cake-websocket)

Introduction
------------

[](#introduction)

This CakePHP 3 plugin gives you an easy way to add websocket capability to your web application.

#### Main Packages

[](#main-packages)

- [Cake Frontend Bridge](https://github.com/scherersoftware/cake-frontend-bridge)
- [Ratchet](https://github.com/ratchetphp/Ratchet)
- [CakePHP Queuesadilla](https://github.com/josegonzalez/cakephp-queuesadilla)

#### Requirements

[](#requirements)

- CakePHP 3.3 or higher
- PHP 7.1

---

Usage in 4 easy steps
---------------------

[](#usage-in-4-easy-steps)

**Note:** You can checkout our [CakePHP App Template](https://github.com/scherersoftware/cake-app-template) for testing it on a clean app setup with preinstalled dependencies.

#### 1. Define a new event

[](#1-define-a-new-event)

**Example for `websocket_events.php`**

```
...
'userDataUpdated' => [
    'audience' => [
        'includeAllNotAuthenticated' => false,
        'includeAllAuthenticated' => true
    ]
]
...

```

#### 2. Publish the event in server context (e.g. Shell, Controller, Table...)

[](#2-publish-the-event-in-server-context-eg-shell-controller-table)

**Example for `UsersController.php`**

```
...
use Websocket\Lib\Websocket;
...
if ($this->Users->save($exampleUser)) {
    Websocket::publishEvent('userDataUpdated', ['editedUserId' => $exampleUser->id]);
}
...

```

#### 3. Let the client receive the event and define a callback

[](#3-let-the-client-receive-the-event-and-define-a-callback)

**Example for `../users/index_controller.js`**

```
...
App.Websocket.onEvent('userDataUpdated', function(payload) {
    if (payload.editedUserId === this.exampleUser.id) {
        alert('Someone changed the data of this user!');
    }
}.bind(this));
...

```

#### 4. Run the websocket server shell and start testing!

[](#4-run-the-websocket-server-shell-and-start-testing)

```
$ bin/cake websocket_server

```

---

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

[](#installation)

#### 1. Require the plugin

[](#1-require-the-plugin)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require scherersoftware/cake-websocket

```

#### 2. Load the plugin

[](#2-load-the-plugin)

The next step is to load the plugin properly inside your bootstrap.php:

```
Plugin::load('Websocket', ['bootstrap' => true, 'routes' => true]);

```

#### 3. Configure app config

[](#3-configure-app-config)

- **File:** `/config/app.php`

    ```
