Exemplo n.º 1
0
        $this->result = ob_get_contents();
        ob_end_clean();
        echo "server: handshake success with fd{$request->fd}\n";
        $server->push($request->fd, $this->result);
    }
    public function onMessage($server, $frame)
    {
        //print_r($server->connection_info($frame->fd));
        echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        $server->push($frame->fd, json_encode(['a' => 'demo']));
    }
    public function onClose($ser, $fd)
    {
        print_r($ser->connection_info($fd->fd));
        echo "client {$fd} closed\n";
    }
    public function onShutdown($serv)
    {
        echo PHP_EOL . date("Y-m-d H:i:s") . " server shutdown!" . PHP_EOL;
    }
    // 获取实例对象
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}
WebSocket::getInstance();