http://socketo.me/docs/deploy#evented-io-extensions
https://github.com/reactphp/event-loop#exteventloop
Connections | stream_select | libevent |
---|---|---|
100 | 10.656 | 9.298 |
500 | 11.175 | 9.791 |
800 | 17.327 | 9.709 |
1000 | 23.282 | 9.749 |
https://www.pigo.idv.tw/archives/589
wampserver_broadcast: ['127.0.0.1:8095', '127.0.0.1:8097', '127.0.0.1:8099']
$key = array_search($this->websocket_this_node, $this->wampserver_broadcast);
unset($this->wampserver_broadcast[$key]);
bin/console server:run --port=8095
bin/console server:run --port=8097
bin/console server:run --port=8099
upstream socket {
server 127.0.0.1:8095;
server 127.0.0.1:8097;
server 127.0.0.1:8099;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
server_name 127.0.0.1;
listen 8090;
proxy_next_upstream error;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header Host $http_host;
location / {
proxy_pass http://socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 86400; # neccessary to avoid websocket timeout disconnect
proxy_redirect off;
}
}
http://nginx.org/en/docs/http/load_balancing.html http://nginx.org/en/docs/http/websocket.html
-
composer req andreybolonin/ratchet-multi-instance
-
Inject
use RatchetMultiInstanceTrait;
into your Topic class -
Add
broadcast/channel
into you Topic class
public function onPublish(ConnectionInterface $connection, $topic, $event, array $exclude, array $eligible)
{
switch ($topic->getId()) {
case 'counter/channel':
$this->CounterTopic($connection, $topic, $event, $exclude, $eligible);
break;
case 'price/channel':
$this->PriceTopic($connection, $topic, $event, $exclude, $eligible);
break;
case 'broadcast/channel':
$this->BroadcastTopic($connection, $topic, $event, $exclude, $eligible);
break;
}
}
- Send the
$topic->broadcast($event)
with$this->broadcast($event)
for broadcasting in another WampServer nodes