Giter Club home page Giter Club logo

pathfinder_websocket's Introduction

WebSocket server for Pathfinder

Requirements

  • PHP (≥ v7.1)
  • A working instance of Pathfinder (≥ v2.0.0-rc.1)
  • Composer to install packages for the WebSocket server

Install

  1. Checkout this project in a new folder e.g. /var/www/websocket.pathfinder
  2. Install Composer
  3. Install Composer dependencies from composer.json file:
  • $ cd /var/www/websocket.pathfinder
  • $ composer install
  1. Start WebSocket server $ php cmd.php

Configuration

Default

Clients (WebBrowser) listen for connections

  • Host: 0.0.0.0. (=> any client can connect)
  • Port: 8020
  • ↪ URI: 127.0.0.1:8020

(=> Your WebServer (e.g. Nginx) should proxy all WebSocket connections to this source)

TCP TcpSocket connection (Internal use for WebServer ⇄ WebSocket server communication)

  • Host: 127.0.0.1 (=> Assumed WebServer and WebSocket server running on the same machine)
  • Port: 5555
  • ↪ URI: tcp://127.0.0.1:5555

(=> Where Pathfinder reaches the WebSocket server. This must match SOCKET_HOST, SOCKET_PORT options in environment.ini)

Start parameters [Optional]

The default configuration should be fine for most installations. You can change/overwrite the default Host and Port configuration by adding additional CLI parameters when starting the WebSocket server:

$ php cmd.php --wsHost [CLIENTS_HOST] --wsPort [CLIENTS_PORT] --tcpHost [TCP_HOST] --tcpPort [TCP_PORT] --debug 0

For example: If you want to change the the WebSocket port and increase debug output:

$ php cmd.php --wsPort 8030 --debug 3

--debug (default --debug 2)

Allows you to set log output level from 0 (silent) - errors are not logged, to 3 (debug) for detailed logging.

alt text

WebSocket UI

There is a WebSocket section on Pathinders /setup page. After the WebSocket server is started, you should check it if everything works. You see the most recent WebSocket log entries, the current connection state, the current number of active connections and all maps that have subscriptions

alt text

Log entry view. Depending on the --debug parameter, the most recent (max 50) entries will be shown:

alt text

Subscriptions for each map:

alt text

Unix Service (systemd)

New Service

It is recommended to wrap the cmd.php script in a Unix service, that over control the WebSocket server. This creates a systemd service on CentOS7:

  1. $ cd /etc/systemd/system
  2. $ vi websocket.pathfinder.service
  3. Copy script and adjust ExecStart and WorkingDirectory values:
[Unit]
Description = WebSocket server (Pathfinder) [LIVE] environment
After = multi-user.target

[Service]
Type = idle
ExecStart = /usr/bin/php /var/www/websocket.pathfinder/pathfinder_websocket/cmd.php
WorkingDirectory = /var/www/websocket.pathfinder/pathfinder_websocket
TimeoutStopSec = 0
Restart = always
LimitNOFILE = 10000
Nice = 10

[Install]
WantedBy = multi-user.target

Now you can use the service to start/stop/restart your WebSocket server

  • $ systemctl start websocket.pathfinder.service
  • $ systemctl restart websocket.pathfinder.service
  • $ systemctl stop websocket.pathfinder.service

Auto-Restart the Service

You can automatically restart your service (e.g. on EVE-Online downtime). Create a new "timer" for the automatic restart.

  1. $ cd /etc/systemd/system (same dir as before)
  2. $ vi restart.websocket.pathfinder.timer
  3. Copy script:
[Unit]
Description = Restart timer (EVE downtime) for WebSocket server [LIVE]

[Timer]
OnCalendar = *-*-* 12:01:00
Persistent = true

[Install]
WantedBy = timer.target

Now we need a new "restart service" for the timer:

  1. $ cd /etc/systemd/system (same dir as before)
  2. $ vi restart.websocket.pathfinder.service
  3. Copy script:
[Unit]
Description = Restart (periodically)  WebSocket server [LIVE]

[Service]
Type = oneshot
ExecStart = /usr/bin/systemctl try-restart websocket.pathfinder.service

And then, we need to either restart the machine or launch

systemctl start restart.websocket.pathfinder.timer

Info

  • Ratchet - "WebSockets for PHP"
  • ReactPHP - "Event-driven, non-blocking I/O with PHP"

pathfinder_websocket's People

Contributors

exodus4d avatar fumbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pathfinder_websocket's Issues

Installation question

Hi,

i have limited knowledge in this server setup stuff - especially nginx - so i have no idea on how to install the websockets properly. I hope someone can point me in the right direction, please.

So far i have a local working pathfinder setup (all green, except websockets) on a virtualbox, network bridged debian stretch server called "debian". I can reach it with http://debian in my network.

  • pathfinder is located in /var/www/pathfinder (pathfinder.conf in /etc/nginx/sites...)

  • websocket is located in /var/www/pathfinder_websockets (i "git cloned it" and executed composer install, adjusted owner and permissions, no errors)

  • I can start "php cmd.php" and it seems to be running.

But http://debian/setup can not see it. I guess i am missing some steps.

Is it ok to install the websocket in a new directory in /var/www ?
Do i need another nginx config for the websocket in /etc/nginx/sites...?
Do i need to add something to the pathfinder.conf in /etc/nginx/sites...?
Both of the last?

Matthl

Socket connection test fails.

I'm running into an issue with the testWebSocket failing on the /setup route.

Here's the output of php cmd.php

2017-02-15 05:27:15 Server START ------------------------------------------
PHP Notice:  Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408

Notice: Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412
PHP Notice:  Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408

Notice: Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412
PHP Notice:  Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408

Notice: Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412
PHP Notice:  Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408

Notice: Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412
PHP Notice:  Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408

Notice: Undefined index: load in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 408
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 409
PHP Notice:  Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

Notice: Undefined index: task in /home/forge/pathfinder_websocket/app/Main/MapUpdate.php on line 412

It seems to be failing somewhere around here: https://github.com/exodus4d/pathfinder/blob/master/public/js/v1.2.0/app/setup.js#L4222

I added a var_dump( $data ) at app/Main/MapUpdate.php on line 407 to see what was happening during the test. It returned the first healthCheck task and proper data but afterwards it looked like it was sending some blank data causing it to fail.

I haven't been able to dive into it too much but wanted to reported in case anyone had ideas.

Segmentation fault

The WebSocket server is working great (client can connect) but I keep having this error "Segmentation fault", which of course crash the websocket server. It seems to happen when a client disconnect.

Any idea of what it could be ?

Websocket server using 100% of CPU all the time

I recently configured Websockets for my own Pathfinder instance, and immediately upon starting the websocket server from this project, it uses all the CPU on my AWS server (t2.small) even without any incoming connections. For everything else on the server (mysql, php-fpm, nginx, etc.) performance has never been an issue as I have a small number of users.

Because of this, Websockets actually perform worse for me than the fallback Ajax method as the server takes longer to respond to requests.

I initially configured websockets for v.1.2.0, but performed the upgrade process all the way to v.1.2.3 to see if that would help, and it has not (this is what I expected, since it is the websocket server that is the problem, and this project has not changed recently).

Here is the rest of the server information from my /setup page:
image

If you need any other diagnostic information please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.