发布于 2015-08-09 09:43:00 | 282 次阅读 | 评论: 0 | 来源: 网络整理
从管道中读取数据。
int swoole_process->read(int $buffer_size=8192);
$buffer_size是缓冲区的大小,默认为8192,最大不超过64K
这里是同步阻塞读取的,可以使用swoole_event_add将管道加入到事件循环中,变为异步模式
示例:
function callback_function_async(swoole_process $worker)
{
$GLOBALS['worker'] = $worker;
swoole_event_add($worker->pipe, function($pipe) {
$worker = $GLOBALS['worker'];
$recv = $worker->read();
echo "From Master: $recvn";
//send data to master
$worker->write("hello mastern");
sleep(2);
$worker->exit(0);
});
}