Skip to content

如何让 Hyperf 只启动一个服务 #3091

Answered by limingxinleo
limingxinleo asked this question in Q&A
Discussion options

You must be logged in to vote

作为 Hyperf 作者,接到过很多这类需求和 PR,但都被我毙了,因为框架提供了极大的自由度,这些东西完全可以自己扩展。

以下我们提供一种极为友好的方式,处理这个问题。

DEMO

如何扩展

先让我们阅读一下 Symfony\Component\Console\Application 中的一段代码

$event = new ConsoleCommandEvent($command, $input, $output);
$e = null;

try {
    $this->dispatcher->dispatch($event, ConsoleEvents::COMMAND);

    if ($event->commandShouldRun()) {
        $exitCode = $command->run($input, $output);
    } else {
        $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
    }
} catch (\Throwable $e) {
    $event = new ConsoleErrorEvent($input, $output, $e, $command);
    $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
    $e = $event->getError();

    if (0 === $exitCode = $event->getExitC…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@huangdijia
Comment options

@limingxinleo
Comment options

Answer selected by limingxinleo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants