Download the PHP package consik/yii2-websocket without Composer

On this page you can find all versions of the php package consik/yii2-websocket. 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-websocket

Yii2 WebSocketServer

Latest Stable Version Total Downloads License

Used Ratchet

Installation

The preferred way to install this extension is through composer.

Either run

or add

WebSocketServer class description

Properties

    • Port number for websocket server
    • Close connection or not when error occurs with it
    • Check client's messages for commands or not
    • IOServer object
    • Storage of connected clients

Methods

Events

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

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

Class events\ExceptionEvent - Triggered when throwed Exception on binding socket

Class events\WSClientEvent - Triggered when client connected to the server

Class events\WSClientEvent - Triggered when client close connection with server

Class events\WSClientErrorEvent - Triggered when an error occurs on a Connection

Class events\WSClientMessageEvent - Triggered when message recieved from client

Class events\WSClientCommandEvent - Triggered when controller starts user's command

Class events\WSClientCommandEvent - Triggered when controller finished user's command

Examples

Simple echo server

Create your server class based on WebSocketServer. For example :

Create yii2 console controller for starting server:

Start your server using console:

php yii server/start

Now let's check our server via js connection:

Console result must be:

Connection established!

Hey!

Response:Hey!

Handle server starting success and error events

Now we try handle socket binding error and open it on other port, when error occurs;

Create yii2 console controller for starting server:

Start your server using console command:

php yii server/start

Server console result must be:

Error opening port 80

Server started at port 81

Recieving client commands

You can implement methods that will be runned after some of user messages automatically;

Server class :

Run the server like in examples above

Check connection and command working by js script:

Console result must be:

ping

Response:Pong

Chat example

In the end let's make simple chat with sending messages and function to change username;

Code without comments, try to understand it by youself ;)

Enjoy ;)

Other

Starting yii2 console application as daemon using nohup


All versions of yii2-websocket with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
cboden/ratchet Version 0.3.*
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 consik/yii2-websocket contains the following files

Loading the files please wait ....