PHP code example of yiiplus / yii2-websocket
1. Go to this page and download the library: Download yiiplus/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/ */
yiiplus / yii2-websocket example snippets
namespace xxx\channels;
class PushMessageChannel extends BaseObject implements \yiiplus\websocket\ChannelInterface
{
public function execute($fd, $data)
{
return [
$fd, // 第一个参数返回客户端ID,多个以数组形式返回
$data // 第二个参数返回需要返回给客户端的消息
];
}
public function close($fd)
{
return;
}
}
Yii::$app->websocket->send(['channel' => 'push-message', 'message' => '用户 xxx 送了一台飞机!']);