workerman长时间未连接,无法发送消息,第二次即可正常发送,

mwz747512353

问题描述

workerman长时间未连接,无法发送消息,第二次即可正常发送,且报错think\exception\ErrorException: Packets out of order. Expected 1 received 0. Packet size=145

程序代码或配置

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | Workerman设置 仅对 php think worker:server 指令有效
// +----------------------------------------------------------------------
return [
    // 扩展自身需要的配置
    'protocol'       => 'websocket', // 协议 支持 tcp udp unix http websocket text
    'host'           => '0.0.0.0', // 监听地址
    'port'           => 2345, // 监听端口
    'socket'         => '', // 完整监听地址
    'ssl'   =>  true,
    'context'        => [
        'ssl' => [
            'local_cert'  => 'D:/phpEnv/server/nginx/conf/vhosts/cert/www.fzhelpr.com.pem', // 也可以是crt文件
            'local_pk'    => 'D:/phpEnv/server/nginx/conf/vhosts/cert/www.fzhelpr.com-key.pem',
            'verify_peer' => false,
        ],
    ], // socket 上下文选项
    'worker_class'   => 'app\api\http\Worker', // 自定义Workerman服务类名 支持数组定义多个服务

    // 支持workerman的所有配置参数
    'name'           => 'thinkphp',
    'count'          => 4,
    'daemonize'      => false,
    'pidFile'        => '',

    // 支持事件回调
    // onWorkerStart
    'onWorkerStart'  => function ($worker) {

    },
    // onWorkerReload
    'onWorkerReload' => function ($worker) {

    },
    // onConnect
    'onConnect'      => function ($connection) {

    },
    // onMessage
    'onMessage'      => function ($connection, $data) {
        $connection->send('receive success');
    },
    // onClose
    'onClose'        => function ($connection) {

    },
    // onError
    'onError'        => function ($connection, $code, $msg) {
        echo "error [ $code ] $msg\n";
    },
];

重现问题的步骤

客户端长时间未访问,发送消息给服务器则返回think\exception\ErrorException: Packets out of order. Expected 1 received 0. Packet size=145,然后重连服务器再次发送即可正常

操作系统环境及workerman/webman等具体版本

操作系统Debian GNU/Linux 11
workerman:3.5.34
thinkphp 6.0
php 8.1.13
nginx:1.22.1

1197 1 1
1个回答

walkor 打赏

定时查询下数据库,让数据库连接保持活跃,防止连接不活跃被mysql服务端断开

  • mwz747512353 2023-07-17

    您好,我thinkphp开启断线重连是否也可以

  • walkor 2023-07-17

    你可以试下

  • xiaohuli 2023-12-25

    楼主, 怎么解决的? 相同问题, 定时任务开启后, 过2天就会报错

年代过于久远,无法发表回答
×
🔝