Swoole's server. php global variable data can only be placed in two?

Source: Internet
Author: User
There have been only two clients with four... {Code ...}

There are only two

Four clients are opened...


  Push ($ fd, $ msg) ;}}// listen to the WebSocket connection opening event $ ws-> on ('open', function (swoole_websocket_server $ ws, $ request) use (& $ fds) {$ fds [$ request-> fd] = $ request-> fd; $ ws-> push ($ request-> fd, "Welcome to Meng chat platform \ n"); broadcast ($ ws, "user {$ request-> fd} is logged on! ", $ Fds, $ request-> fd); var_dump ($ fds) ;}); // listens to WebSocket message events $ ws-> on ('message ', function (swoole_websocket_server $ ws, $ frame) use (& $ fds) {$ msg = 'from '. $ frame-> fd. ": {$ frame-> data} \ n"; broadcast ($ ws, $ msg, $ fds, $ frame-> fd ); // $ ws-> push ($ frame-> fd, "server: {$ frame-> data }"); // $ ws-> push ($ frame-> fd, "server: {$ frame-> data }");}); // listen to the WebSocket connection close event $ ws-> on ('close', function (swoole_websocket_server $ Ws, $ fd) use (& $ fds) {unset ($ fds [$ fd]); broadcast ($ ws, "user {$ fd} is offline! ", $ Fds) ;}); $ ws-> start ();

Reply content:

There are only two

Four clients are opened...


  Push ($ fd, $ msg) ;}}// listen to the WebSocket connection opening event $ ws-> on ('open', function (swoole_websocket_server $ ws, $ request) use (& $ fds) {$ fds [$ request-> fd] = $ request-> fd; $ ws-> push ($ request-> fd, "Welcome to Meng chat platform \ n"); broadcast ($ ws, "user {$ request-> fd} is logged on! ", $ Fds, $ request-> fd); var_dump ($ fds) ;}); // listens to WebSocket message events $ ws-> on ('message ', function (swoole_websocket_server $ ws, $ frame) use (& $ fds) {$ msg = 'from '. $ frame-> fd. ": {$ frame-> data} \ n"; broadcast ($ ws, $ msg, $ fds, $ frame-> fd ); // $ ws-> push ($ frame-> fd, "server: {$ frame-> data }"); // $ ws-> push ($ frame-> fd, "server: {$ frame-> data }");}); // listen to the WebSocket connection close event $ ws-> on ('close', function (swoole_websocket_server $ Ws, $ fd) use (& $ fds) {unset ($ fds [$ fd]); broadcast ($ ws, "user {$ fd} is offline! ", $ Fds) ;}); $ ws-> start ();

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.