exodus4d/pathfinder_websocket 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

exodus4d/pathfinder_websocket

Composer 安装命令:

composer require exodus4d/pathfinder_websocket

包简介

WebSocket extension for 'Pathfinder'

README 文档

README

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"

exodus4d/pathfinder_websocket 适用场景与选型建议

exodus4d/pathfinder_websocket 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 exodus4d/pathfinder_websocket 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 exodus4d/pathfinder_websocket 我们能提供哪些服务?
定制开发 / 二次开发

基于 exodus4d/pathfinder_websocket 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-20