Swoole-src: PHP Warning: Swoole\WebSocket\Server::push(): the connected client of connection[49] is not a websocket client or closed.

Created on 6 Dec 2018  ·  2Comments  ·  Source: swoole/swoole-src

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.
   public function onRequest(\swoole_http_request $request, \swoole_http_response $response)
    {
        $data = [
            'message' => $request->post['info']
        ];
        foreach ($this->webSocketServ->connections as $fd) {
            try {
                $this->webSocketServ->push($fd, json_encode($data));
            } catch (Exception $e) {

            }
        }
    }
  1. What did you expect to see?

客户端关闭后应该就开始触发 close ,client 已经从 $server->connections 中移除才对 ,为什么会报这个错误 ?

  1. What did you see instead?

PHP Warning: Swoole\WebSocket\Server::push(): the connected client of connection[49] is not a websocket client or closed.

  1. What version of Swoole are you using (show your php --ri swoole)?
[root@localhost 09]# php --ri swoole

swoole

swoole support => enabled
Version => 4.2.9
Author => Swoole Group[email: [email protected]]
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (including version of kernel & php & gcc) ?
[root@localhost 09]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
question

All 2 comments

发送期间客户端可能会断开的, 而你遍历的PHP迭代器是不可能实时更新的, 在发送的时候底层会再次获取连接, 如果发现客户端断开了就会警告, 你可以加个@抑制警告, 这个在群发时没有影响, 可以安心@.

使用WebSocket\Server->isEstablished判断fd是否为可用的websocket连接

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daslicht picture daslicht  ·  4Comments

Gemorroj picture Gemorroj  ·  3Comments

chenye2017 picture chenye2017  ·  3Comments

lotarbo picture lotarbo  ·  4Comments

rovico picture rovico  ·  4Comments