swoole-framwork/boot.php

43 lines
1.4 KiB
PHP
Raw Normal View History

2024-05-20 11:51:07 +08:00
<?php
2024-05-21 14:33:56 +08:00
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . "/app/config/define.php";
\Swoole\Runtime::enableCoroutine(true);
2024-06-26 17:13:45 +08:00
//手撸一个自己的swoole框架
2024-05-31 14:57:01 +08:00
// command swoole-cli boot.php start
2024-05-20 11:51:07 +08:00
use Swoole\Process;
2024-06-05 09:16:08 +08:00
if ($argc >= 2) {
2024-05-20 11:51:07 +08:00
$cmd = $argv[1];
2024-05-21 14:33:56 +08:00
if ($cmd == 'start') {
2024-06-05 09:16:08 +08:00
$daemonize = false;
if ($argc == 3 && $argv[2] == '-d') {
$daemonize = true;
}
2024-06-26 17:13:45 +08:00
$http = new Core\server\HttpServer($daemonize);
2024-05-20 11:51:07 +08:00
$http->run();
2024-05-21 14:33:56 +08:00
} 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);
2024-06-05 09:16:08 +08:00
$daemonize = false;
if ($argc == 3 && isset($argv[2]) && $argv == '-d') {
$daemonize = true;
}
2024-06-26 17:13:45 +08:00
$http = new Core\server\HttpServer($daemonize);
2024-05-21 14:33:56 +08:00
echo "restart done" . PHP_EOL;
$http->run();
} else {
echo "restart the failure" . PHP_EOL;
2024-05-20 11:51:07 +08:00
}
} else {
echo '无效命令';
}
2024-06-26 17:13:45 +08:00
}else{
echo '请输入命令: swoole-cli boot.php start';
2024-05-21 14:33:56 +08:00
}