initial 2.0.0-a4 commit

This commit is contained in:
jerry
2020-11-03 21:02:24 +08:00
parent da584e0542
commit 29fa9d8662
48 changed files with 794 additions and 1470 deletions

View File

@@ -17,7 +17,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ZM\Config\ZMConfig;
use ZM\Console\Console;
use ZM\Store\ZMBuf;
use ZM\Store\ZMAtomic;
use ZM\Utils\HttpUtil;
class PureHttpCommand extends Command
@@ -28,7 +28,7 @@ class PureHttpCommand extends Command
protected function configure() {
$this->setDescription("Run a simple http server | 启动一个简单的文件 HTTP 服务器");
$this->setHelp("直接运行可以启动");
$this->addArgument('dir', InputArgument::OPTIONAL, 'Your directory');
$this->addArgument('dir', InputArgument::REQUIRED, 'Your directory');
$this->addOption("host", 'H', InputOption::VALUE_REQUIRED, "启动监听地址");
$this->addOption("port", 'P', InputOption::VALUE_REQUIRED, "启动监听地址的端口");
// ...
@@ -36,19 +36,23 @@ class PureHttpCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output) {
$tty_width = explode(" ", trim(exec("stty size")))[1];
if(realpath($input->getArgument('dir') ?? '.') === false) {
$output->writeln("<error>Directory error(".($input->getArgument('dir') ?? '.')."): no such file or directory.</error>");
return self::FAILURE;
}
$global = ZMConfig::get("global");
$host = $input->getOption("host") ?? $global["host"];
$port = $input->getOption("port") ?? $global["port"];
$server = new Server($host, $port);
$server->set(ZMConfig::get("global", "swoole"));
Console::init(0, $server);
ZMBuf::$atomics["request"] = [];
ZMAtomic::$atomics["request"] = [];
for ($i = 0; $i < 32; ++$i) {
ZMBuf::$atomics["request"][$i] = new Atomic(0);
ZMAtomic::$atomics["request"][$i] = new Atomic(0);
}
$index = ["index.html", "index.htm"];
$server->on("request", function (Request $request, Response $response) use ($input, $index, $server) {
ZMBuf::$atomics["request"][$server->worker_id]->add(1);
ZMAtomic::$atomics["request"][$server->worker_id]->add(1);
HttpUtil::handleStaticPage(
$request->server["request_uri"],
$response,
@@ -62,7 +66,7 @@ class PureHttpCommand extends Command
Process::signal(SIGINT, function () use ($server) {
Console::warning("Server interrupted by keyboard.");
for ($i = 0; $i < 32; ++$i) {
$num = ZMBuf::$atomics["request"][$i]->get();
$num = ZMAtomic::$atomics["request"][$i]->get();
if($num != 0)
echo "[$i]: ".$num."\n";
}

View File

@@ -15,19 +15,23 @@ class RunServerCommand extends Command
protected static $defaultName = 'server';
protected function configure() {
$this->setDefinition([
new InputOption("debug-mode", "D", null, "开启调试模式 (这将关闭协程化)"),
new InputOption("log-debug", null, null, "调整消息等级到debug (log-level=4)"),
new InputOption("log-verbose", null, null, "调整消息等级到verbose (log-level=3)"),
new InputOption("log-info", null, null, "调整消息等级到info (log-level=2)"),
new InputOption("log-warning", null, null, "调整消息等级到warning (log-level=1)"),
new InputOption("log-error", null, null, "调整消息等级到error (log-level=0)"),
new InputOption("log-theme", null, InputOption::VALUE_REQUIRED, "改变终端的主题配色"),
new InputOption("disable-console-input", null, null, "禁止终端输入内容 (后台服务时需要)"),
new InputOption("disable-coroutine", null, null, "关闭协程Hook"),
new InputOption("daemon", null, null, "以守护进程的方式运行框架"),
new InputOption("watch", null, null, "监听 src/ 目录的文件变化并热更新"),
new InputOption("env", null, InputOption::VALUE_REQUIRED, "设置环境类型 (production, development, staging)"),
]);
$this->setDescription("Run zhamao-framework | 启动框架");
$this->setHelp("直接运行可以启动");
$this->addOption("debug-mode", "D", null, "开启调试模式 (这将关闭协程化)");
$this->addOption("log-debug", null, null, "调整消息等级到debug (log-level=4)");
$this->addOption("log-verbose", null, null, "调整消息等级到verbose (log-level=3)");
$this->addOption("log-info", null, null, "调整消息等级到info (log-level=2)");
$this->addOption("log-warning", null, null, "调整消息等级到warning (log-level=1)");
$this->addOption("log-error", null, null, "调整消息等级到error (log-level=0)");
$this->addOption("log-theme", null, InputOption::VALUE_REQUIRED, "改变终端的主题配色");
$this->addOption("disable-console-input", null, null, "禁止终端输入内容 (后台服务时需要)");
$this->addOption("disable-coroutine", null, null, "关闭协程Hook");
$this->addOption("watch", null, null, "监听 src/ 目录的文件变化并热更新");
$this->addOption("env", null, InputOption::VALUE_REQUIRED, "设置环境类型 (production, development, staging)");
// ...
}