发布于 2015-08-09 09:43:55 | 1116 次阅读 | 评论: 0 | 来源: 网络整理
投递数据到消息队列中。
bool swoole_process->push(string $data);
示例
$workers = [];
$worker_num = 2;
for($i = 0; $i < $worker_num; $i++)
{
$process = new swoole_process('callback_function', false, false);
$process->useQueue();
$pid = $process->start();
$workers[$pid] = $process;
//echo "Master: new worker, PID=".$pid."n";
}
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."n";
//recv data from master
$recv = $worker->pop();
echo "From Master: $recvn";
sleep(2);
$worker->exit(0);
}
foreach($workers as $pid => $process)
{
$process->push("hello worker[$pid]n");
}
for($i = 0; $i < $worker_num; $i++)
{
$ret = swoole_process::wait();
$pid = $ret['pid'];
unset($workers[$pid]);
echo "Worker Exit, PID=".$pid.PHP_EOL;
}