Skip to content
New issue

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

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

Already on GitHub? # to your account

请问这个库如何连接websocket??? #4

Closed
alfuckk opened this issue Jul 24, 2019 · 1 comment
Closed

请问这个库如何连接websocket??? #4

alfuckk opened this issue Jul 24, 2019 · 1 comment

Comments

@alfuckk
Copy link

alfuckk commented Jul 24, 2019

希望科普或者提供链接科普一下。
我用这个库后台跑起来了socket:9501服务。
然后就不知道怎么弄了,目的是直接连接ws

@lanlin
Copy link
Owner

lanlin commented Jul 26, 2019

@STEFEIN 感觉你对我写的这个东西可能有什么误解。
image

个人建议

codeigniter-swoole 是本地监听模式,写的时候也没有考虑外部监听或者前端直连的情景。
采用的是 swoole 的 TCP + SWOOLE_PROCESS + SWOOLE_UNIX_STREAM 的模式。
至于你希望创建的 websocket 服务器模式,请参考 swoole 官方文档自行构建,谢谢。

如何创建 Swoole WebSocket服务器

codeigniter-swoole 的主要应用场景

codeigniter-swoole 的目的在于处理 “框架内” 的耗时逻辑以及定时任务的拆分执行。
可以认为主要针对,local 对 local 的形式,换句话说就是只在当前服务器内部完成。

场景:你的某个请求需要执行一段耗时很久的逻辑,例如从远程服务器下载一个文件,并进行转码后再上传回去替换原文件。 fpm 下默认 30秒 就超时了,而且你也不能让用户一直挂着请求等你执行完毕。

那么这个时候,最简单的做法就是从原请求中用 swoole client 投递一个 task 到 swoole server,然后结束当前的请求。让 swoole server 在 cli 模式下拉起一个进程来单独执行这段耗时逻辑。从而避免超时等问题。

codeigniter-swoole 就是这样做的,当然还能处理一些定时类的任务。
拆分出来的逻辑也走的是 CI 路由调度的执行路线,等同于发一个新的 url 请求到某个控制器一样。

这个就是个针对人少事情多的一个解决方案。
所有东西都在一个框架中,减少开发难度和开发量,减少维护难度。
这就是我写这个小东西的初衷,不用进行项目或者框架拆分,又或者引入第三方的一堆玩意。
所有东西都在同一个框架下面,开发起来更简单快速。

lanlin added a commit that referenced this issue Jul 26, 2019
codeigniter-swoole 的主要应用场景 #4
@lanlin lanlin closed this as completed Jul 29, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants