Download the PHP package blackbes/yii2-yiisockets without Composer

On this page you can find all versions of the php package blackbes/yii2-yiisockets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-yiisockets

Websockets for Yii2

PHP Websockets with Yii2 integration based on Ratchet.

Installation

he preferred way to install this extension is through composer.

1) Clone this project in any directory. In this case it will be located in upper level folder

2) In your project's composer.lock add following lines:

3) Run composer install in the project root

4) Add following lines to your config/console.php. Note that provided model should be the one you use to perform authorisation in your app. (Should implement Identity Interface)

5) Add SocketController.php (you can find template here) to your commands folder

6) Add ecosystem.config.js (you can find template here) to your project root directory

7) Install npm

8) Install pm2

Usage on back

1) Create sockets folder in your root directory

2) Add controllers that extends blackbes\yiisockets\BaseController

4) Start server

5) Start pm2

BaseController Overview

Extending this controller will provide following methods that you can use in your websocket controllers:

Method Parameters Returns Example usage
send() ConnectionInterface $conn, string $group_id, mixed data none $this->send($this->conn, 'get-new-text', ['text' => $text]);
sendError() ConnectionInterface $conn, string $error_text none ---
sendToGroupExcludeClient() string $action, mixed $data, string $group_id, bool $is_json boolean $this->sendToGroup('new-message', ['text' => $text], 'chat-'.$chatId);
sendToGroupExcludeUser() string $action, mixed $data, string $group_id, bool $is_json boolean $this->sendToGroup('new-message', ['text' => $text], 'chat-'.$chatId);
sendToGroup() string $action, mixed $data, string $group_id, bool $is_json boolean $this->sendToGroup('new-message', ['text' => $text], 'chat-'.$chatId);
addToGroup() ConnectionInterface $conn, string $group_id boolean $this->addToGroup($this->conn,'chat-'.$chatId);
removeFromGroup() ConnectionInterface $conn, string $group_id boolean $this->removeFromGroup($this->conn,'chat-'.$chatId);
isInGroup() ConnectionInterface $conn, string $group_id boolean ---
GetGroup() string $group_id mixed - All connections from specific group ---
getClientId() ConnectionInterface $conn integer - Id of user ---
getData() string $data_name mixed - Specified value that you've sent in request $this->getData('chatId')

Connecting to websockets on front

1) Add Yii2WebSockets file to your JavaScript project and import it

2) Create a variable object login_credentials with following properties:

4) Start WebSocket connection

5) Add actions to listen to. Those will trigger when one of your contollers will use a sendToGroup() method which has same action name

Note that you can add multiple actions

Using websockets on front

1) Use socketSend method to make requests

2) Process responses in your addAction methods


All versions of yii2-yiisockets with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.14
cboden/ratchet Version ^0.4.2
ratchet/pawl Version ^0.3.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package blackbes/yii2-yiisockets contains the following files

Loading the files please wait ....