Rt
Want to use WebSocket instead of polling
How can I configure WebSocket server?
Reply content:
Rt
Want to use WebSocket instead of polling
How can I configure WebSocket server?
PHP itself does not provide websocket related functions, this you have to use a third-party extension, such as peak brother in the development of C-pecl extension swoole, which directly encapsulates the WebSocket Server, such as the official website example:
http://www.swoole.com/
on('Open', function($server, $req) { echo "connection open: ".$req->fd;});$serv->on('Message', function($server, $frame) { echo "message: ".$frame->data; $server->push($frame->fd, json_encode(["hello", "world"]));});$serv->on('Close', function($server, $fd) { echo "connection close: ".$fd;});$serv->start();
Phpwebim is the Swoole official WebSocket Web Instant Chat tool based on the PHP swoole extension and Swoole Framework development. PHPWEBIM supports Websocket+comet two kinds of protocols, Available for all kinds of browsers including IE.
Https://github.com/matyhtf/PHPWebIM
demo:http://webim.swoole.com/
After compiling and installing PHP, you can install the swoole extension by executing php_prefix/bin/pecl install Swoole, as the swoole extension has been included in the PHP official PECL warehouse and has been supported by PHP7:
Https://pecl.php.net/package/swoole