You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
35
vendor/swoole/examples/channel/leader_follower.php
vendored
Executable file
35
vendor/swoole/examples/channel/leader_follower.php
vendored
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
use Swoole\Timer;
|
||||
use Swoole\Process;
|
||||
use Swoole\Channel;
|
||||
|
||||
$chan = new Channel(1024 * 256);
|
||||
|
||||
$worker_num = 4;
|
||||
$workers = array();
|
||||
|
||||
for ($i = 0; $i < $worker_num; $i++)
|
||||
{
|
||||
$process = new Process(function ($worker) use ($chan, $i)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
$data = $chan->pop();
|
||||
if (empty($data))
|
||||
{
|
||||
usleep(200000);
|
||||
continue;
|
||||
}
|
||||
echo "worker#$i\t$data\n";
|
||||
}
|
||||
}, false);
|
||||
$process->id = $i;
|
||||
$pid = $process->start();
|
||||
$workers[$pid] = $process;
|
||||
}
|
||||
|
||||
Timer::tick(2000, function () use ($chan)
|
||||
{
|
||||
static $index = 0;
|
||||
$chan->push("hello-" . $index++);
|
||||
});
|
Reference in New Issue
Block a user