Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev: 2.0 #454

Merged
merged 12 commits into from Jul 3, 2019

update add an common method for server commands

  • Loading branch information...
inhere committed Jul 3, 2019
commit 3d1d0d848a8f5ca31a09feb5ee860079f7c018e4
@@ -13,7 +13,7 @@
use Swoft\Server\Command\BaseServerCommand;
use Swoft\Server\Exception\ServerException;
use Swoft\Server\ServerInterface;
use function ucfirst;
use function strtoupper;
use function bean;
use function input;
use function output;
@@ -79,18 +79,7 @@ public function start(): void
];
// Port Listeners
$listeners = $server->getListener();
foreach ($listeners as $name => $listener) {
if (!$listener instanceof ServerInterface) {
continue;
}
$upperName = ucfirst($name);
$panel[$upperName] = [
'listen' => sprintf('%s:%s', $listener->getHost(), $listener->getPort()),
'type' => $listener->getTypeName()
];
}
$panel = $this->appendPortsToPanel($server, $panel);
Show::panel($panel);
@@ -3,8 +3,11 @@
namespace Swoft\Server\Command;
use Swoft\Server\Server;
use Swoft\Server\ServerInterface;
use Swoft\Stdlib\Helper\Sys;
use function input;
use function sprintf;
use function strtoupper;
use function trim;
/**
@@ -45,4 +48,30 @@ protected function getFullCommand(): string
return sprintf('%s %s %s', $phpBin, $script, $command);
}
/**
* @param Server $server
* @param array $panel
*
* @return array
*/
protected function appendPortsToPanel(Server $server, array $panel): array
{
// Port Listeners
$listeners = $server->getListener();
foreach ($listeners as $name => $listener) {
if (!$listener instanceof ServerInterface) {
continue;
}
$upperName = strtoupper($name);
$panel[$upperName] = [
'listen' => sprintf('%s:%s', $listener->getHost(), $listener->getPort()),
'type' => $listener->getTypeName()
];
}
return $panel;
}
}
@@ -54,7 +54,8 @@ public function beans(): array
{
return [
'tcpServer' => [
'on' => [
'port' => 18309,
'on' => [
SwooleEvent::CONNECT => bean(ConnectListener::class),
SwooleEvent::CLOSE => bean(CloseListener::class),
SwooleEvent::RECEIVE => bean(ReceiveListener::class),
@@ -16,8 +16,6 @@
use function input;
use function output;
// use Swoft\Helper\EnvHelper;
/**
* Class WsServerCommand
*
@@ -65,27 +63,27 @@ public function start(): void
// Server startup parameters
$mainHost = $server->getHost();
$mainPort = $server->getPort();
$modeName = $server->getModeName();
$typeName = $server->getTypeName();
// TCP 启动参数
// $tcpStatus = $server->getTcpSetting();
// $httpEnable = $server->hasListener(SwooleEvent::REQUEST);
Show::panel([
// Main server
$panel = [
'WebSocket' => [
'listen' => $mainHost . ':' . $mainPort,
'type' => $typeName,
'mode' => $modeName,
'type' => $server->getTypeName(),
'mode' => $server->getModeName(),
'worker' => $workerNum,
],
'Extra' => [
// 'httpHandle' => $httpEnable,
'pidFile' => $server->getPidFile(),
],
]);
// 'Extra' => [
// 'httpHandle' => $httpEnable,
// 'pidFile' => $server->getPidFile(),
// ],
];
// Port Listeners
$panel = $this->appendPortsToPanel($server, $panel);
Show::panel($panel);
output()->writef('<success>Server start success !</success>');
output()->writef('<success>WebSocket Server start success !</success>');
// Start the server
$server->start();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.