This commit is contained in:
2020-09-07 15:19:13 +08:00
parent ae5a0eaf11
commit fceaf7e6fb
3 changed files with 207 additions and 3 deletions
+40 -1
View File
@@ -41,6 +41,8 @@ use Swoole\Runtime;
*/
class Server extends Application
{
use Action;
const HTTP = 'HTTP';
const TCP = 'TCP';
const PACKAGE = 'PACKAGE';
@@ -58,7 +60,6 @@ class Server extends Application
/** @var Http|Websocket|Packet|Receive */
private $baseServer;
/**
* @param array $configs
* @return Http|Packet|Receive|Websocket
@@ -92,10 +93,48 @@ class Server extends Application
{
$configs = Config::get('servers', true);
$baseServer = $this->initCore($configs);
foreach ($configs as $config) {
if ($this->isUse($config['port'])) {
return $this->error('Port ' . $config['host'] . '::' . $config['port'] . ' is already.');
}
}
$baseServer->start();
}
/**
* @return bool
*/
public function isRunner()
{
if (empty($this->port)) {
return false;
}
if (Snowflake::isLinux()) {
exec('netstat -tunlp | grep ' . $this->port, $output);
} else {
exec('lsof -i :' . $this->port . ' | grep -i "LISTEN"', $output);
}
if (!empty($output)) {
return true;
}
return false;
}
/**
* @return void
*
* start server
* @throws Exception
*/
public function shutdown()
{
$this->stop($this);
}
/**
* @param bool $isEnable
*/