在使用swoole携程时候,怎样实现等待效果咧,下面我们学习一下
use Swoole\Coroutine as co;
// 协程
$time = microtime(true);
// 创建10个协程
for($i = 0; $i < 10; ++$i)
{
// 创建协程
go(function() use($i){
co::sleep(1.0); //模拟等待io操作
echo $i, PHP_EOL;
});
}
swoole_event_wait();
echo 'co time:', microtime(true) - $time, ' s', PHP_EOL;