This commit is contained in:
wandoubaba 2023-10-16 11:40:55 +08:00
parent 67a3eda692
commit 85ded3c5d1
6 changed files with 26 additions and 43 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.buildpath .buildpath
composer.lock composer.lock
vendor/ vendor/
.env

View File

@ -18,7 +18,7 @@ require_once __DIR__ . '/Clients/StatisticClient.php';
require_once __DIR__.'/Protocols/JsonNL.php'; require_once __DIR__.'/Protocols/JsonNL.php';
// 开启的端口 // 开启的端口
$worker = new Worker('JsonNL://0.0.0.0:2015'); $worker = new Worker('JsonNL://0.0.0.0:' . $_ENV['RPC_PORT'] ?: '2015');
// 启动多少服务进程 // 启动多少服务进程
$worker->count = 16; $worker->count = 16;
// worker名称php start.php status 时展示使用 // worker名称php start.php status 时展示使用
@ -27,7 +27,7 @@ $worker->name = 'JsonRpc';
$worker->onMessage = function($connection, $data) $worker->onMessage = function($connection, $data)
{ {
$statistic_address = 'udp://127.0.0.1:55656'; $statistic_address = 'udp://127.0.0.1:' . $_ENV['STATISTIC_WORKER_PORT'] ?: '55656';
// 判断数据是否正确 // 判断数据是否正确
if(empty($data['class']) || empty($data['method']) || !isset($data['param_array'])) if(empty($data['class']) || empty($data['method']) || !isset($data['param_array']))
{ {
@ -78,7 +78,6 @@ $worker->onMessage = function($connection, $data)
}; };
// 如果不是在根目录启动则运行runAll方法 // 如果不是在根目录启动则运行runAll方法
if(!defined('GLOBAL_START')) if(!defined('GLOBAL_START'))
{ {

View File

@ -20,18 +20,18 @@ use Bootstrap\StatisticWorker;
use \Workerman\Worker; use \Workerman\Worker;
use \Workerman\WebServer; use \Workerman\WebServer;
// StatisticProvider // StatisticProvider
$statistic_provider = new StatisticProvider("Text://0.0.0.0:55858"); $statistic_provider = new StatisticProvider("Text://0.0.0.0:" . $_ENV['STATISTIC_PROVIDER_PORT'] ?: '55858');
$statistic_provider->name = 'StatisticProvider'; $statistic_provider->name = 'StatisticProvider';
// StatisticWorker // StatisticWorker
$statistic_worker = new StatisticWorker("Statistic://0.0.0.0:55656"); $statistic_worker = new StatisticWorker("Statistic://0.0.0.0:" . $_ENV['STATISTIC_WORKER_PORT'] ?: '55656');
$statistic_worker->transport = 'udp'; $statistic_worker->transport = 'udp';
$statistic_worker->name = 'StatisticWorker'; $statistic_worker->name = 'StatisticWorker';
// WebServer // WebServer
$web = new WebServer("http://0.0.0.0:55757"); $web = new WebServer("http://0.0.0.0:" . $_ENV['STATISTIC_WEB_PORT'] ?: '55757');
$web->name = 'StatisticWeb'; $web->name = 'StatisticWeb';
$web->addRoot('www.your_domain.com', __DIR__.'/Web'); $web->addRoot($_ENV['DOMAIN'] ?: 'localhost', __DIR__.'/Web');
// recv udp broadcast // recv udp broadcast
$udp_finder = new Worker("Text://0.0.0.0:55858"); $udp_finder = new Worker("Text://0.0.0.0:" . $_ENV['STATISTIC_PROVIDER_PORT'] ?: '55858');
$udp_finder->name = 'StatisticFinder'; $udp_finder->name = 'StatisticFinder';
$udp_finder->transport = 'udp'; $udp_finder->transport = 'udp';
$udp_finder->onMessage = function ($connection, $data) $udp_finder->onMessage = function ($connection, $data)

View File

@ -5,6 +5,7 @@
"homepage": "http://www.workerman.net", "homepage": "http://www.workerman.net",
"license" : "MIT", "license" : "MIT",
"require": { "require": {
"workerman/statistics" : ">=1.0.0" "workerman/statistics" : ">=1.0.0",
"vlucas/phpdotenv": "^5.5"
} }
} }

47
start
View File

@ -2,40 +2,17 @@
service_name="workerman-jsonrpc" service_name="workerman-jsonrpc"
compose_file="docker-compose-dev.yml" compose_file="docker-compose-dev.yml"
if [ $# -eq 0 ] || [ $1 == "start" ] if ! docker inspect -f '{{.State.Running}}' $service_name >/dev/null 2>&1; then
then if ! docker-compose -f $compose_file up -d >/dev/null 2>&1; then
docker rm -f $service_name if ! docker compose -f $compose_file up -d >/dev/null 2>&1; then
docker-compose -f $compose_file up -d echo "Failed to start the container using docker-compose or docker compose."
docker exec $service_name php start.php start exit 1
else
docker rm -f $service_name
docker-compose -f $compose_file up -d
docker exec $service_name php start.php "$@"
fi#!/bin/bash
service_name="workerman-jsonrpc"
compose_file="docker-compose-dev.yml"
if [ $# -eq 0 ] || [ $1 == "start" ]
then
docker rm -f $service_name
if docker-compose -f $compose_file up -d; then
docker exec $service_name php start.php start
else
if docker compose -f $compose_file up -d; then
docker exec $service_name php start.php start
else
echo "Failed to start the container using docker-compose or docker compose."
fi
fi
else
docker rm -f $service_name
if docker-compose -f $compose_file up -d; then
docker exec $service_name php start.php "$@"
else
if docker compose -f $compose_file up -d; then
docker exec $service_name php start.php "$@"
else
echo "Failed to start the container using docker-compose or docker compose."
fi
fi fi
fi
fi
if [ $# -eq 0 ] || [ $1 == "start" ]; then
docker exec $service_name php start.php restart
else
docker exec $service_name php start.php "$@"
fi fi

View File

@ -23,10 +23,15 @@ define('GLOBAL_START', 1);
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// 加载.env文件
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
// 加载所有Applications/*/start.php以便启动所有服务 // 加载所有Applications/*/start.php以便启动所有服务
foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file) foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file)
{ {
require_once $start_file; require_once $start_file;
} }
// 运行所有服务 // 运行所有服务
Worker::runAll(); Worker::runAll();