This commit is contained in:
2021-03-04 14:40:33 +08:00
parent 486daf639a
commit 5d1a3b3533
10 changed files with 67 additions and 42 deletions
+2 -1
View File
@@ -131,13 +131,14 @@ trait Action
/**
* @param $port
* @return bool|array
* @throws Exception
*/
private function isUse($port): bool|array
{
if (empty($port)) {
return false;
}
if (Snowflake::isLinux()) {
if (Snowflake::getPlatform()->isLinux()) {
exec('netstat -tunlp | grep ' . $port, $output);
} else {
exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
+1 -1
View File
@@ -31,7 +31,7 @@ class OnManagerStart extends Callback
$events = Snowflake::app()->getEvent();
$events->trigger(Event::SERVER_MANAGER_START, [$server]);
if (!Snowflake::isLinux()) {
if (!Snowflake::getPlatform()->isLinux()) {
return;
}
name(Config::get('id', false, 'system') . ' Server Manager.');
+1 -1
View File
@@ -25,7 +25,7 @@ class OnStart extends Callback
public function onHandler(Server $server)
{
Snowflake::setProcessId($server->master_pid);
if (Snowflake::isLinux()) {
if (Snowflake::getPlatform()->isLinux()) {
name(Config::get('id', false, 'system:') . ' master.');
}
$event = Snowflake::app()->getEvent();
+2 -10
View File
@@ -51,7 +51,6 @@ class OnWorkerStart extends Callback
/**
* @param Server $server
* @param int $worker_id
* @param $prefix
* @throws ComponentException
* @throws ConfigException
*/
@@ -59,11 +58,7 @@ class OnWorkerStart extends Callback
{
putenv('environmental=' . Snowflake::TASK);
$prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid);
$start = microtime(true);
fire(Event::SERVER_TASK_START);
$this->debug(sprintf('%s use time %s', $prefix, microtime(true) - $start));
$this->set_process_name($server, $worker_id);
}
@@ -82,12 +77,8 @@ class OnWorkerStart extends Callback
Snowflake::setWorkerId($server->worker_pid);
putenv('environmental=' . Snowflake::WORKER);
$prefix = sprintf('%s #%d Pid:%d start.', ucfirst(env('environmental')), $worker_id, $server->worker_pid);
try {
$start = microtime(true);
fire(Event::SERVER_WORKER_START, [$worker_id]);
$this->debug(sprintf('%s use time %s', $prefix, microtime(true) - $start));
} catch (\Throwable $exception) {
$this->addError($exception);
write($exception->getMessage(), 'worker');
@@ -101,6 +92,7 @@ class OnWorkerStart extends Callback
* @param $worker_id
* @return string
* @throws ConfigException
* @throws Exception
*/
private function set_process_name($socket, $worker_id): mixed
{
@@ -110,7 +102,7 @@ class OnWorkerStart extends Callback
} else {
$name = $prefix . ' worker: No.' . $worker_id;
}
if (Snowflake::isMac()) {
if (Snowflake::getPlatform()->isMac()) {
return 1;
}
return swoole_set_process_name($name);
+2 -1
View File
@@ -177,6 +177,7 @@ class Server extends HttpService
/**
* @return bool
* @throws ConfigException
* @throws Exception
*/
public function isRunner(): bool
{
@@ -185,7 +186,7 @@ class Server extends HttpService
return false;
}
foreach ($port as $value) {
if (Snowflake::isLinux()) {
if (Snowflake::getPlatform()->isLinux()) {
exec('netstat -tunlp | grep ' . $value['port'], $output);
} else {
exec('lsof -i :' . $value['port'] . ' | grep -i "LISTEN"', $output);