2017 © Pedro Peláez
 

library ratchet-multi-instance

Ratchet multi instance

image

andreybolonin/ratchet-multi-instance

Ratchet multi instance

  • Tuesday, April 10, 2018
  • by andreybolonin
  • Repository
  • 3 Watchers
  • 4 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

QuickStart

0) Check, do you install high perfomance ext-event extension (libevent)

http://socketo.me/docs/deploy#evented-io-extensions, (*1)

https://github.com/reactphp/event-loop#exteventloop, (*2)

https://bitbucket.org/osmanov/pecl-event/src/530d542a9e828ad23063a483164e6ff15aee157b/INSTALL.md?fileviewer=file-view-default, (*3)

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, (*4)

1) Define your pool (config/services.yaml)

wampserver_broadcast: ['127.0.0.1:8095', '127.0.0.1:8097', '127.0.0.1:8099'], (*5)

2) Exclude this node

$key = array_search($this->websocket_this_node, $this->wampserver_broadcast);, (*6)

unset($this->wampserver_broadcast[$key]);, (*7)

3) Run your nodes

bin/console server:run --port=8095, (*8)

bin/console server:run --port=8097, (*9)

bin/console server:run --port=8099, (*10)

4) Setup NGINX (as load balancer)

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, (*11)

Installation

1) composer req andreybolonin/ratchet-multi-instance, (*12)

2) Inject use RatchetMultiInstanceTrait; into your Topic class, (*13)

3) Add broadcast/channel into you Topic class, (*14)

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;
    }
}

4) Send the $topic->broadcast($event) with $this->broadcast($event) for broadcasting in another WampServer nodes, (*15)

Arch

, (*16)

5) Symfony Bundle

https://github.com/andreybolonin/RatchetBundle, (*17)

The Versions

10/04 2018

dev-master

9999999-dev

Ratchet multi instance

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrey Bolonin
by Igor Bondarenko