Yii2结合swoole控制台做websocket服务器

<?php
/**
 * websocket
 */

namespace app\console\swoole;

use Yii;

class WssController extends \yii\console\Controller
{
    private $serv;
    public function __construct()
    {
        $this->serv = new \swoole_websocket_server("0.0.0.0", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
        $this->serv->set(array(
            'ssl_cert_file' => '/idata/ssl/co.digua.test/trustasia.crt',
            'ssl_key_file' => '/idata/ssl/co.digua.test/trustasia.key',
        ));
        $this->serv->on('open', array($this, 'onOpen'));
        $this->serv->on('message', array($this, 'onMessage'));
        $this->serv->on('close', array($this, 'onClose'));
        $this->serv->start();
    }

    public function onOpen($serv, $req)
    {
        echo "connection open: {$req->fd}\n";
        var_dump($req);
    }
    public function onMessage(\swoole_websocket_server $serv, $frame)
    {
        echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        $serv->push($frame->fd, "this is server");
    }

    public function onClose($serv, $fd, $from_id)
    {
        echo "Client {$fd} close connection\n";
    }
}