Skip to content

Commit

Permalink
3.6.3-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Feb 22, 2023
1 parent 2532dfa commit 27b1419
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 57 deletions.
12 changes: 4 additions & 8 deletions src/Bridge/DefaultCommand/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use EasySwoole\Bridge\Package;
use EasySwoole\EasySwoole\Bridge\AbstractCommand;
use EasySwoole\EasySwoole\Command\Utility;
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\Core;
use EasySwoole\EasySwoole\ServerManager;
use EasySwoole\EasySwoole\Task\TaskManager;
Expand All @@ -17,17 +19,11 @@ public function commandName(): string
return 'status';
}

protected function server(Package $package, Package $responsePackage)
protected function call(Package $package, Package $responsePackage)
{
$data = ServerManager::getInstance()->getSwooleServer()->stats();
$data['runMode'] = Core::getInstance()->runMode();
$data = Utility::createServerDisplayItem(Config::getInstance()) + $data;
$responsePackage->setArgs($data);
return true;
}

protected function task(Package $package, Package $responsePackage)
{
$responsePackage->setArgs(TaskManager::getInstance()->status());
return true;
}
}
58 changes: 9 additions & 49 deletions src/Command/DefaultCommand/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,15 @@ protected function start()
$conf = Config::getInstance();
// php easyswoole.php server start -d
$daemonize = CommandManager::getInstance()->issetOpt('d');

if ($daemonize) {
$conf->setConf("MAIN_SERVER.SETTING.daemonize", $daemonize);
}

$serverType = $conf->getConf('MAIN_SERVER.SERVER_TYPE');
$displayItem = [];
switch ($serverType) {
case EASYSWOOLE_SERVER:
{
$serverType = 'SWOOLE_SERVER';
break;
}
case EASYSWOOLE_WEB_SERVER:
{
$serverType = 'SWOOLE_WEB';
break;
}
case EASYSWOOLE_WEB_SOCKET_SERVER:
{
$serverType = 'SWOOLE_WEB_SOCKET';
break;
}
default:
{
$serverType = 'UNKNOWN';
}
}
$displayItem['main server'] = $serverType;
$displayItem['listen address'] = $conf->getConf('MAIN_SERVER.LISTEN_ADDRESS');
$displayItem['listen port'] = $conf->getConf('MAIN_SERVER.PORT');
$data = $conf->getConf('MAIN_SERVER.SETTING');
if (empty($data['user'])) {
$data['user'] = get_current_user();
if (empty($conf->getConf('MAIN_SERVER.SETTING.user'))) {
$conf->setConf('MAIN_SERVER.SETTING.user',get_current_user());
}
$displayItem = $displayItem + $data;
$displayItem['swoole version'] = phpversion('swoole');
$displayItem['php version'] = phpversion();
$displayItem['easyswoole version'] = SysConst::EASYSWOOLE_VERSION;
$displayItem['run mode'] = Core::getInstance()->runMode();
$displayItem['temp dir'] = EASYSWOOLE_TEMP_DIR;
$displayItem['log dir'] = EASYSWOOLE_LOG_DIR;

$displayItem = Utility::createServerDisplayItem(Config::getInstance());
$msg = Color::green(Utility::easySwooleLog()) . "\n";
foreach ($displayItem as $key => $value) {
$msg .= Utility::displayItem($key, $value) . "\n";
Expand Down Expand Up @@ -184,19 +150,13 @@ protected function status()
$run = new Scheduler();
$run->add(function () use (&$result) {
$result = Utility::bridgeCall('status', function (Package $package) {
$data = $package->getArgs();
$data['start_time'] = date('Y-m-d H:i:s', $data['start_time']);

$final = [];

foreach ($data as $key => $val){
$final[] = [
'item'=>$key,
'value'=>$val
];
$displayItem = $package->getArgs();
$msg = Color::green(Utility::easySwooleLog()) . "\n";
foreach ($displayItem as $key => $value) {
$msg .= Utility::displayItem($key, $value) . "\n";
}
return new ArrayToTextTable($final);
}, 'server');
return $msg;
}, 'call');
});
$run->start();
return $result;
Expand Down
42 changes: 42 additions & 0 deletions src/Command/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use EasySwoole\Bridge\Package;
use EasySwoole\Command\Color;
use EasySwoole\EasySwoole\Bridge\Bridge;
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\Core;
use EasySwoole\EasySwoole\SysConst;
use EasySwoole\Utility\File;

class Utility
Expand Down Expand Up @@ -45,6 +48,45 @@ static function displayItem($name, $value)
return "\e[32m" . str_pad($name, 30, ' ', STR_PAD_RIGHT) . "\e[34m" . $value . "\e[0m";
}

static function createServerDisplayItem(Config $conf)
{
$serverType = $conf->getConf('MAIN_SERVER.SERVER_TYPE');
$displayItem = [];
switch ($serverType) {
case EASYSWOOLE_SERVER:
{
$serverType = 'SWOOLE_SERVER';
break;
}
case EASYSWOOLE_WEB_SERVER:
{
$serverType = 'SWOOLE_WEB';
break;
}
case EASYSWOOLE_WEB_SOCKET_SERVER:
{
$serverType = 'SWOOLE_WEB_SOCKET';
break;
}
default:
{
$serverType = 'UNKNOWN';
}
}
$displayItem['main server'] = $serverType;
$displayItem['listen address'] = $conf->getConf('MAIN_SERVER.LISTEN_ADDRESS');
$displayItem['listen port'] = $conf->getConf('MAIN_SERVER.PORT');
$data = $conf->getConf('MAIN_SERVER.SETTING');
$displayItem = $displayItem + $data;
$displayItem['swoole version'] = phpversion('swoole');
$displayItem['php version'] = phpversion();
$displayItem['easyswoole version'] = SysConst::EASYSWOOLE_VERSION;
$displayItem['run mode'] = Core::getInstance()->runMode();
$displayItem['temp dir'] = EASYSWOOLE_TEMP_DIR;
$displayItem['log dir'] = EASYSWOOLE_LOG_DIR;
return $displayItem;
}

public static function releaseResource($source, $destination,$confirm = false)
{
$filename = basename($destination);
Expand Down

0 comments on commit 27b1419

Please sign in to comment.