修改plugin.webman.channel.server端口号为2207

This commit is contained in:
2026-03-25 17:52:05 +08:00
parent 60833aa6ff
commit 6c6971c4bf
4 changed files with 40 additions and 6 deletions

View File

@@ -19,6 +19,11 @@ REDIS_PORT=6379
REDIS_PASSWORD=''
REDIS_DB=1
# webman channel用于定时任务通信
WEBMAN_CHANNEL_HOST=127.0.0.1
WEBMAN_CHANNEL_PORT=2207
WEBMAN_CHANNEL_LISTEN_HOST=0.0.0.0
# 游戏地址,用于 /api/v1/getGameUrl 返回
GAME_URL=dice-game-v3.yuliao666.top

View File

@@ -16,9 +16,15 @@
use Webman\Channel\Server;
use Workerman\Protocols\Frame;
$listenHost = env('WEBMAN_CHANNEL_LISTEN_HOST', '0.0.0.0');
$listenPort = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($listenPort === false) {
$listenPort = 2207;
}
return [
'server' => [
'listen' => 'frame://0.0.0.0:2207',
'listen' => 'frame://' . $listenHost . ':' . $listenPort,
'protocol' => Frame::class,
'handler' => Server::class,
'reloadable' => false,

View File

@@ -20,6 +20,20 @@ use plugin\saiadmin\exception\ApiException;
*/
class CrontabLogic extends BaseLogic
{
/**
* 获取 webman channel 服务地址
* 需要保证与 server/config/plugin/webman/channel/process.php 的 listen 端口一致
*/
private function channelConfig(): array
{
$host = env('WEBMAN_CHANNEL_HOST', '127.0.0.1');
$port = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($port === false) {
$port = 2207;
}
return ['host' => $host, 'port' => $port];
}
/**
* 构造函数
*/
@@ -67,7 +81,8 @@ class CrontabLogic extends BaseLogic
$id = $model->getKey();
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
return true;
@@ -116,7 +131,8 @@ class CrontabLogic extends BaseLogic
]);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
}
@@ -141,7 +157,8 @@ class CrontabLogic extends BaseLogic
$result = parent::destroy($ids);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $ids]);
}
return $result;
@@ -162,7 +179,8 @@ class CrontabLogic extends BaseLogic
$result = $model->save(['status' => $status]);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
}
return $result;

View File

@@ -20,8 +20,13 @@ class Task
$dbName = env('DB_NAME');
if (!empty($dbName)) {
$this->logic = new CrontabLogic();
$channelHost = env('WEBMAN_CHANNEL_HOST', '127.0.0.1');
$channelPort = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($channelPort === false) {
$channelPort = 2207;
}
// 连接webman channel服务
Client::connect();
Client::connect($channelHost, $channelPort);
// 订阅某个自定义事件并注册回调,收到事件后会自动触发此回调
Client::on('crontab', function ($data) {
$this->reload($data);