-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to "share" connections between multiple servers #1089
Comments
Using the channel service component, it can communicate across servers/processes. The process is for the ws1 server to notify the ws2 server using the channel service component, and then the ws2 server sends data to the specified client. https://manual.workerman.net/doc/en/components/channel-examples.html |
Ok, but it assumes only one Channel\Server... and I don't want to have one centralized service... maybe I can just connect one server to another also by a websocket? |
Yes, you can. |
ok and is there a way how to use workerman (or other component from workerman family) as a websocket client? because right now I'm using Ratchet\Pawl, but there is no support for php 8.4 and the whole project seems little bit dead... thank you. |
See example for AsyncTcpConnection |
ok, i created a function like this:
but for sending ping I implemented own mechanism:
is there any implementation included in the library? thank you... |
The AsyncTcpConnection has its own reconnect() method and does not need to be implemented again. Change $connection->onClose = function () {
$this->connectServers(isRestart: true);
};
$connection->onError = function () {
$this->connectServers(isRestart: true);
}; to $connection->onClose = function ($connection) {
$connection->reconnect(static::ReconnectInterval);
}; |
ok and how does it recognize without pingpong that the connection is really live or dead? because the connection can be in "hang" state - client thinks it's still alive but it isn't (because of firewall, server shutdown without TCP RST and so on)... |
To timely detect a connection drop, heartbeat detection is essential. |
ok so shouldn't a heartbeat be implemented directly into AsyncTcpConnection with parameter "interval"? |
Using a timer and adding an interval parameter in AsyncTcpConnection is not significantly different: Timer::add(50, function() use ($connection) {
$connection->send('ping');
}); $connection->setInterval(50, function($connection) {
$connection->send('ping');
}); Perhaps future versions will consider adding it. |
Hi,
we have 2 servers for high availability and load balancing. I'm using workerman as websocket server.
Device 1 connects to server 1, device 2 connects to server 2. Device 1 sends message to server 1. What is the best way to send it to server 2 and then to device 2?
Thank you for your advice.
The text was updated successfully, but these errors were encountered: