入门指引 Server Client Process AsyncIO Memory HttpServer WebSocket 高级 其他

发布于 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);
    });
}
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务