JavaScript-How to configure the WebSocket server, using the Segmentfault

Source: Internet
Author: User
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

  • 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.