swoole 协程通道 为了协程直接互相通讯传递数据 

和go的通道很相似

 

Co\run(function(){
    $chan = new Swoole\Coroutine\Channel(1);
    Swoole\Coroutine::create(function () use ($chan) {
        for($i = 0; $i < 100000; $i++) {
            co::sleep(1.0);
            $chan->push(['rand' => rand(1000, 9999), 'index' => $i]);
            echo "$i\n";
        }
    });
    Swoole\Coroutine::create(function () use ($chan) {
        while(1) {
            $data = $chan->pop();
            var_dump($data);
        }
    });
});

 

相关文章:

  • 2021-11-13
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2019-12-03
  • 2022-12-23
猜你喜欢
  • 2022-01-24
  • 2021-06-13
  • 2021-05-18
  • 2022-12-23
  • 2021-09-17
  • 2021-12-23
相关资源
相似解决方案