Home > PHP Framework > Swoole > body text

How swoole manages the cluster

藏色散人
Release: 2020-04-10 09:56:22
Original
3185 people have browsed it

How swoole manages the cluster

How does swoole manage the cluster?

How to do swoole websocket server cluster?

Question:

1. How to achieve automatic rotation in the swoole websocket cluster to ensure reliability

2. In the swoole websocket server cluster, how to let the client of server1 A pushes information to client B of server2?

Answer:

First of all, you need to understand that the essence of the problem is that you are not in the same process space (of course on a different server), and you cannot communicate directly because tcp cannot be shared. The connection or the corresponding tcp connection cannot be directly operated

Now if you have multiple machines with the same service in a cluster (as one working process every day): A and B

Now you want to The idea of ​​communicating from a certain connection (a certain client) to a certain connection (a certain client) in B:

Start a server M

In the startup process of A and B, open a connection M Clients (we call them C1 and C2 respectively), and listen to events

A certain connection (a certain client) in A sends a message to the A server, the A server processes the relevant B-identified user data, transfers it to C1, and then C1 sends a message to the M server

Then the M server sends a message to all connected clients (of course, if you make the corresponding user ID and identify C2, you can directly send the message to C2)

M sends a message to C2, and then C2 finds a specific connection in B based on the identifier, and then sends the message directly

The above is the detailed content of How swoole manages the cluster. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!