<?php
$server = new swoole_websocket_server('php', 9501);
$server->on('start', function (swoole_websocket_server $server) {
echo "Server has been started!\n";
});
$server->on('open', function (swoole_websocket_server $server, $request) {
echo "websocket: new connection, id: {$request->fd}\n";
});
$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "websocket: {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "Replying, you sent " . $frame->data);
});
$server->on('close', function (swoole_websocket_server $server, $fd) {
echo "websocket: connection with id {$fd} has been closed\n";
});
$server->start();
<?php
$server = new swoole_websocket_server('php', 9501);
$server->on('start', function (swoole_websocket_server $server) {
echo "Server has been started!\n";
});
$server->on('open', function (swoole_websocket_server $server, $request) {
echo "websocket: new connection, id: {$request->fd}\n";
});
$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "websocket: {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "Replying, you sent " . $frame->data);
});
$server->on('close', function (swoole_websocket_server $server, $fd) {
echo "websocket: connection with id {$fd} has been closed\n";
});
$server->start();