Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

协程websocketk客户端咨询 #55

Closed
excxapp opened this issue May 7, 2019 · 5 comments
Closed

协程websocketk客户端咨询 #55

excxapp opened this issue May 7, 2019 · 5 comments

Comments

@excxapp
Copy link

excxapp commented May 7, 2019

协程方式开启websocket客户端。
请问,框架可以实现吗

比如我想后端连接第三方提供的websocket,动态建立多个socket隧道,并保持监听状态。
动态增加隧道数量这样的需求,框架里面有实现swoole里面的Coroutine\Socket吗?

image

@onanying
Copy link
Member

onanying commented May 7, 2019

框架暂时没有封装 swoole 的协程客户端,客户端 swoole 官方提供的本来就高度封装,大家可以直接使用。

@onanying
Copy link
Member

onanying commented May 7, 2019

后续版本可能我会增加

@excxapp
Copy link
Author

excxapp commented May 7, 2019

好的,辛苦大佬。
另外,协程池这个,如何使用,我是要作为
消息队列(MQ)消费处理(发送邮件、短信)
这种用途,能给一个简单的发邮件的例子吗
比如消费rabbitmq或者redis的简单demo
刚接触这个框架,不是很明白使用。

@onanying
Copy link
Member

onanying commented May 7, 2019

官网有这个demo的链接:Mix PHP V2 实例:协程池异步邮件发送守护程序 https://www.jianshu.com/p/ea635ad7fa9d

@onanying
Copy link
Member

https://www.kancloud.cn/onanying/mixphp2/1002219

go(function () {
    $cli = new \Swoole\Coroutine\http\Client("127.0.0.1", 9502);
    $ret = $cli->upgrade("/websocket");
    if ($ret) {
        $cli->push('{"method":"join.room","params":{"roomid":1010},"id":1}');
        while (true) {
            $data = $cli->recv();
            if ($data === false) {
                echo "disconnect" . PHP_EOL;
                break;
            }
            var_dump($data);
        }
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants