Skip to content

Commit db928d1

Browse files
committed
✨ add quitServer method
Signed-off-by: otengkwame <[email protected]>
1 parent b5a3d9a commit db928d1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Core/core/Console/Console.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,51 @@ private static function serve($args = []): void
971971
static::runSystemCommand("php -S {$host}:" . $port . " -t " . $dir);
972972
}
973973

974+
/**
975+
* Quit Webby Server
976+
*
977+
* @param array $args Console arguments
978+
* @param integer $ttq Time given to quit server
979+
* @return void
980+
*/
981+
public static function quitServer(array $args = [], int $ttq = 10): void
982+
{
983+
984+
$count = $ttq;
985+
$port = static::DEFAULT_PORT;
986+
987+
if (isset($args[3]) && $args[3] === '--port') {
988+
$port = (int)$args[2];
989+
}
990+
991+
if (isset($args[4]) && ($args[4] === '--in' || $args[4] === 'in')) {
992+
$count = (int)$args[5];
993+
}
994+
995+
echo ConsoleColor::yellow("\n\tQuitting Webby Server on Port: {$port} \n\t\t");
996+
997+
while($count > 0)
998+
{
999+
echo ConsoleColor::yellow(".");
1000+
sleep(1);
1001+
$count--;
1002+
}
1003+
1004+
echo ConsoleColor::yellow("\n\tDone! \n\n");
1005+
1006+
$os = (stripos(PHP_OS, "WIN") === 0) ? "WINDOWS" : "UNIX";
1007+
1008+
static::consoleEnv();
1009+
1010+
if ($os === "WINDOWS") {
1011+
exec("netstat -ano | findstr :{$port}");
1012+
exit;
1013+
}
1014+
1015+
exec("fuser -n tcp -k {$port}");
1016+
1017+
}
1018+
9741019
/**
9751020
* Run Webby Console
9761021
*
@@ -990,6 +1035,8 @@ public static function run(array $args): void
9901035
Console::serve();
9911036
} else if (isset($args[1]) && $args[1] === 'set' && @$args[2] === '--env') {
9921037
Console::setenv();
1038+
} else if (isset($args[1]) && $args[1] === 'quit') {
1039+
Console::quitServer($args);
9931040
} /*else if (isset($args[1]) && $args[1] === '--help') {
9941041
Console::showHelp();
9951042
}*/ else if (!empty($args[1])) {

0 commit comments

Comments
 (0)