PHP code example of goodizer / yii2-websocket
1. Go to this page and download the library: Download goodizer/yii2-websocket library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
goodizer / yii2-websocket example snippets
'components' => [
...
'websocketServer' => [
'class' => 'goodizer\websocket\Server',
'commandClass' => 'console\extensions\Commands',//Your class that inherit goodizer\websocket\Commands
'host' => $params['websocketServer']['host'] ?? 'localhost',
'port' => $params['websocketServer']['port'] ?? 8000,
'isSecure' => $params['websocketServer']['isSecure'] ?? false,
'localCert' => $params['websocketServer']['localCert'] ?? null,
'localPk' => $params['websocketServer']['localPk'] ?? null,
],
...
],
namespace console\controllers;
use Yii;
use yii\console\Controller;
use goodizer\websocket\Server;
/**
* Class WebsocketServerController
* @package console\controllers
*/
class WebsocketServerController extends Controller
{
/**
* @throws \Exception
*/
public function actionStart()
{
/** @var Server $server */
$server = Yii::$app->websocketServer;
$server->start();
}
}
/** @var goodizer\websocket\Client $client */
$client = Yii::$app->get('websocketClient');
$client->send(json_encode(['method' => 'foo', 'params' => ['bar' => true]]));
$ php composer.phar