Skip to content

Commit 1e5d54c

Browse files
authored
Merge pull request #51 from xudianyang/master
* 调整processType标识
2 parents 4a2eff3 + ec0c265 commit 1e5d54c

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

src/MSFServer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function beforeSwooleStart()
122122
} else {
123123
$reloadProcess = new \swoole_process(function ($process) {
124124
new Inotify($this->config, $this);
125-
$this->onWorkerStart($this->server, 0);
125+
$this->onWorkerStart($this->server, null);
126126
}, false, 2);
127127
$this->server->addProcess($reloadProcess);
128128
}
@@ -132,7 +132,7 @@ public function beforeSwooleStart()
132132
if ($this->config->get('config_manage_enable', false)) {
133133
$configProcess = new \swoole_process(function ($process) {
134134
new Config($this->config, $this);
135-
$this->onWorkerStart($this->server, 0);
135+
$this->onWorkerStart($this->server, null);
136136
}, false, 2);
137137
$this->server->addProcess($configProcess);
138138
}
@@ -141,7 +141,7 @@ public function beforeSwooleStart()
141141
if ($this->config->get('user_timer_enable', false)) {
142142
$timerProcess = new \swoole_process(function ($process) {
143143
new Timer($this->config, $this);
144-
$this->onWorkerStart($this->server, 0);
144+
$this->onWorkerStart($this->server, null);
145145
}, false, 2);
146146
$this->server->addProcess($timerProcess);
147147
}
@@ -476,7 +476,8 @@ public function onWorkerStart($serv, $workerId)
476476
{
477477
// Worker类型
478478
if (!$this->isTaskWorker()) {
479-
if ($this->processType == Marco::PROCESS_WORKER) {
479+
if ($workerId !== null) {
480+
$this->processType = Marco::PROCESS_WORKER;
480481
getInstance()->sysTimers[] = swoole_timer_tick(2000, function ($timerId) {
481482
$this->statistics();
482483
});

src/Marco.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ class Marco
109109
*/
110110
const PROCESS_TIMER = 5;
111111

112+
/**
113+
* 进程为MASTER
114+
*/
115+
const PROCESS_MASTER = 4094;
116+
117+
/**
118+
* 进程为MANAGER
119+
*/
120+
const PROCESS_MANAGER = 4095;
121+
112122
/**
113123
* 进程为USER(默认)
114124
*/
@@ -118,12 +128,14 @@ class Marco
118128
* 进程名称
119129
*/
120130
const PROCESS_NAME = [
121-
self::PROCESS_WORKER => 'WORKER',
122-
self::PROCESS_TASKER => 'TASKER',
123-
self::PROCESS_RELOAD => 'RELOAD',
124-
self::PROCESS_CONFIG => 'CONFIG',
125-
self::PROCESS_TIMER => 'TIMER',
126-
self::PROCESS_USER => 'USER',
131+
self::PROCESS_MASTER => 'Master',
132+
self::PROCESS_MANAGER => 'Manager',
133+
self::PROCESS_WORKER => 'Worker',
134+
self::PROCESS_TASKER => 'Tasker',
135+
self::PROCESS_RELOAD => 'Reload',
136+
self::PROCESS_CONFIG => 'Config',
137+
self::PROCESS_TIMER => 'Timer',
138+
self::PROCESS_USER => 'User',
127139
];
128140

129141
/**

src/Server.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class Server extends Child
4040
/**
4141
* @var int 进程类型
4242
*/
43-
public $processType = Marco::PROCESS_WORKER;
43+
public $processType = Marco::PROCESS_MASTER;
4444

4545
/**
4646
* @var Server 实例
@@ -532,9 +532,10 @@ public function beforeSwooleStart()
532532
public function onStart($serv)
533533
{
534534
self::$_masterPid = $serv->master_pid;
535+
$this->processType = Marco::PROCESS_MASTER;
535536
file_put_contents(self::$pidFile, self::$_masterPid);
536537
file_put_contents(self::$pidFile, ',' . $serv->manager_pid, FILE_APPEND);
537-
self::setProcessTitle($this->config['server.process_title'] . '-Master');
538+
self::setProcessTitle($this->config['server.process_title'] . '-' . Marco::PROCESS_NAME[$this->processType]);
538539
}
539540

540541
/**
@@ -647,7 +648,8 @@ public function onWorkerError($serv, $workerId, $workerPid, $exitCode)
647648
*/
648649
public function onManagerStart($serv)
649650
{
650-
self::setProcessTitle($this->config['server.process_title'] . '-Manager');
651+
$this->processType = Marco::PROCESS_MANAGER;
652+
self::setProcessTitle($this->config['server.process_title'] . '-' . Marco::PROCESS_NAME[$this->processType]);
651653
}
652654

653655
/**

0 commit comments

Comments
 (0)