修改plugin.webman.channel.server端口号为2207
This commit is contained in:
@@ -19,6 +19,11 @@ REDIS_PORT=6379
|
|||||||
REDIS_PASSWORD=''
|
REDIS_PASSWORD=''
|
||||||
REDIS_DB=1
|
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 返回
|
# 游戏地址,用于 /api/v1/getGameUrl 返回
|
||||||
GAME_URL=dice-game-v3.yuliao666.top
|
GAME_URL=dice-game-v3.yuliao666.top
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,15 @@
|
|||||||
use Webman\Channel\Server;
|
use Webman\Channel\Server;
|
||||||
use Workerman\Protocols\Frame;
|
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 [
|
return [
|
||||||
'server' => [
|
'server' => [
|
||||||
'listen' => 'frame://0.0.0.0:2207',
|
'listen' => 'frame://' . $listenHost . ':' . $listenPort,
|
||||||
'protocol' => Frame::class,
|
'protocol' => Frame::class,
|
||||||
'handler' => Server::class,
|
'handler' => Server::class,
|
||||||
'reloadable' => false,
|
'reloadable' => false,
|
||||||
|
|||||||
@@ -20,6 +20,20 @@ use plugin\saiadmin\exception\ApiException;
|
|||||||
*/
|
*/
|
||||||
class CrontabLogic extends BaseLogic
|
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();
|
$id = $model->getKey();
|
||||||
// 连接到Channel服务
|
// 连接到Channel服务
|
||||||
ChannelClient::connect();
|
$channel = $this->channelConfig();
|
||||||
|
ChannelClient::connect($channel['host'], $channel['port']);
|
||||||
ChannelClient::publish('crontab', ['args' => $id]);
|
ChannelClient::publish('crontab', ['args' => $id]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -116,7 +131,8 @@ class CrontabLogic extends BaseLogic
|
|||||||
]);
|
]);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
// 连接到Channel服务
|
// 连接到Channel服务
|
||||||
ChannelClient::connect();
|
$channel = $this->channelConfig();
|
||||||
|
ChannelClient::connect($channel['host'], $channel['port']);
|
||||||
ChannelClient::publish('crontab', ['args' => $id]);
|
ChannelClient::publish('crontab', ['args' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +157,8 @@ class CrontabLogic extends BaseLogic
|
|||||||
$result = parent::destroy($ids);
|
$result = parent::destroy($ids);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
// 连接到Channel服务
|
// 连接到Channel服务
|
||||||
ChannelClient::connect();
|
$channel = $this->channelConfig();
|
||||||
|
ChannelClient::connect($channel['host'], $channel['port']);
|
||||||
ChannelClient::publish('crontab', ['args' => $ids]);
|
ChannelClient::publish('crontab', ['args' => $ids]);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
@@ -162,7 +179,8 @@ class CrontabLogic extends BaseLogic
|
|||||||
$result = $model->save(['status' => $status]);
|
$result = $model->save(['status' => $status]);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
// 连接到Channel服务
|
// 连接到Channel服务
|
||||||
ChannelClient::connect();
|
$channel = $this->channelConfig();
|
||||||
|
ChannelClient::connect($channel['host'], $channel['port']);
|
||||||
ChannelClient::publish('crontab', ['args' => $id]);
|
ChannelClient::publish('crontab', ['args' => $id]);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -20,8 +20,13 @@ class Task
|
|||||||
$dbName = env('DB_NAME');
|
$dbName = env('DB_NAME');
|
||||||
if (!empty($dbName)) {
|
if (!empty($dbName)) {
|
||||||
$this->logic = new CrontabLogic();
|
$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服务
|
// 连接webman channel服务
|
||||||
Client::connect();
|
Client::connect($channelHost, $channelPort);
|
||||||
// 订阅某个自定义事件并注册回调,收到事件后会自动触发此回调
|
// 订阅某个自定义事件并注册回调,收到事件后会自动触发此回调
|
||||||
Client::on('crontab', function ($data) {
|
Client::on('crontab', function ($data) {
|
||||||
$this->reload($data);
|
$this->reload($data);
|
||||||
|
|||||||
Reference in New Issue
Block a user