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);
    }

 

swoole多进程通讯实例二

上一篇:linux 解压缩zip


下一篇:Python基础之元组