Javascript-how to configure the WebSocket server and use the SegmentFault

Source: Internet
Author: User
Rt: I want to use websocket instead of polling. How can I configure websocket server rt?
I want to use websocket instead of polling
How can I configure the websocket server?

Reply content:

Rt
I want to use websocket instead of polling
How can I configure the websocket server?

PHP itself does not provide WebSocket-related functions. You need to use third-party extensions. For example, fengge's PECL extension Swoole developed by C, which directly encapsulates WebSocket Server, for example, 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 an official WebSocket webpage instant chat tool developed by Swoole based on PHP Swoole extension and Swoole Framework. PHPWebIM supports WebSocket + Comet protocols and can be used in all types of browsers, including IE.
Https://github.com/matyhtf/PHPWebIM
Demo: http://webim.swoole.com/

After compiling and installing PHP, run PHP_PREFIX/bin/pecl install swoole to install the Swoole extension, because the Swoole extension has been included in the official php pecl repository and supports PHP7:
Https://pecl.php.net/package/swoole

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.