swoole多进程通讯实例二

代码案例思路分析

子进程执行代码执行满足某种条件子进程退出,父进程跟随退出

    $child = new swoole_process("children",false,true);
    function children($process){
        $index = 0;
        while(true){
            $index = $index+1;
            $process->write($index);
            if($index == 10){
                $process->write("exit");
                $process->exit();
            }
            sleep(1);
        }
    }
    $child->start();

    while($index = $child->read()){
        $str = $index.PHP_EOL;
        fwrite(STDOUT,$str);
        if($index == "exit"){
            exit;
        }
        sleep(1);
    }

猜你喜欢

转载自www.cnblogs.com/zh718594493/p/12923255.html