swoole-framwork/boot.php
2024-06-05 09:16:08 +08:00

41 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . "/app/config/define.php";
\Swoole\Runtime::enableCoroutine(true);
// command swoole-cli boot.php start
use Swoole\Process;
use Core\server\HttpServer;
if ($argc >= 2) {
$cmd = $argv[1];
if ($cmd == 'start') {
$daemonize = false;
if ($argc == 3 && $argv[2] == '-d') {
$daemonize = true;
}
$http = new HttpServer($daemonize);
$http->run();
} else if ($cmd == 'stop') {
$getpid = intval(file_get_contents("./Buddha.pid")); //获取上一次程序运行的 master_id
if ($getpid && trim($getpid) != 0) {
Process::kill($getpid);
echo "stop success" . PHP_EOL;
}
} else if ($cmd == 'restart') {
$getpid = intval(file_get_contents("./Buddha.pid")); //获取上一次程序运行的 master_id
if ($getpid && trim($getpid) != 0) {
Process::kill($getpid);
sleep(1);
$daemonize = false;
if ($argc == 3 && isset($argv[2]) && $argv == '-d') {
$daemonize = true;
}
$http = new HttpServer($daemonize);
echo "restart done" . PHP_EOL;
$http->run();
} else {
echo "restart the failure" . PHP_EOL;
}
} else {
echo '无效命令';
}
}