swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

自定义进程中创建子进程,没有创建对应进程数,只会创建一个 #171

Closed aprchen closed 6 years ago

aprchen commented 6 years ago
Q A
Bug report? yes
Feature request? yes/no
Swoft version 1.0.0
Swoole version 2.1.1
PHP version 7.1.4
Runtime environment Win10/Mac/CentOS 7/Ubuntu/Docker etc.

Details

RequestSenderTask::class 只会创建一个


/**
 * Custom process
 *
 * @Process(boot=true)
 */
class MyProcess implements ProcessInterface
{
    public function run(SwoftProcess $process)
    {
        $res = ProcessBuilder::create(RequestSender::NAME)->getProcess();
        $res->start();
    }

    /**
     * @return bool
     * 启动执行条件
     */
    public function check(): bool
    {
        return true;
    }
}

/**
 * Custom process
 *
 * @Process(name="RequestSender",num=2,coroutine=true)
 */
class RequestSender implements ProcessInterface
{
    const NAME = "RequestSender";

    public function run(SwoftProcess $process)
    {
        $process->name(self::NAME);
        /** @var RequestSenderTask $service */
        $service = App::getBean(RequestSenderTask::class);
        $service->runTask();
    }

    public function check(): bool
    {
        return true;
    }
whiteCcinn commented 6 years ago

@aprchen num参数只在boot目录下的父进程中有效,子进程的创建多个是通过 for($i =0, $i < 2; $i++ ) ProcessBuilder::create(RequestSender::NAME)->start()