首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
关于异步启动swoole_websocket_server的问题
我在主进程中运行一个swoole_http_server,在httpServer 启动的时候去task一个swoole_websocket_server,每次运行的时候报一个警告 {{{ PHP Warning: swoole_server::task(): The method can only be used in the worker process. in }}} 后来我在WorkerStart的时候去task webSocketServer,报同样的错误, 同时, task里面的 webSocketServer并没有启动起来 {{{ PHP Warning: swoole_server::__construct(): server is already running. Unable to create swoole_server }}} 我看了所报错的位置,是new swoole_websocket_server的地方。 哎,我是没搞定 我的需求是,第三方通过http调用我的脚本,此时我将调用webSocket通知浏览器,如果websocket与http服务在同的脚本里,运行就在不同的进程里面,而在http服务里面拿不到websocket的句柄。因此我才考虑用异步。请求各位有什么比较好的解决方案么?
发布于7年前 · 7 次浏览 · 来自
提问
二
二节课
我在主进程中运行一个swoole_http_server,在httpServer 启动的时候去task一个swoole_websocket_server,每次运行的时候报一个警告 {{{ PHP Warning: swoole_server::task(): The method can only be used in the worker process. in }}} 后来我在WorkerStart的时候去task webSocketServer,报同样的错误, 同时, task里面的 webSocketServer并没有启动起来 {{{ PHP Warning: swoole_server::__construct(): server is already running. Unable to create swoole_server }}} 我看了所报错的位置,是new swoole_websocket_server的地方。 哎,我是没搞定 我的需求是,第三方通过http调用我的脚本,此时我将调用webSocket通知浏览器,如果websocket与http服务在同的脚本里,运行就在不同的进程里面,而在http服务里面拿不到websocket的句柄。因此我才考虑用异步。请求各位有什么比较好的解决方案么?
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2017-04-29
剑
剑客
错误信息已经说的很清楚了。`task`只能在worker进程内调用,其他地方不可执行。 另外一个server程序只能new一个 swoole_server或swoole_http_server/websocket_server对象。
赞
0
回复
2017-05-03
M
M
可以考虑在http服务里建立一个websocket client连接到你的websocket服务。这样就可以进行相应的通信了。
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。