workerman+tp5的错误问题怎么解决_技术学院_宜昌市隼壹珍商贸有限公司

您好,欢迎访问宜昌市隼壹珍商贸有限公司

400 890 5375
当前位置: 主页 > 新闻动态 > 技术学院

workerman+tp5的错误问题怎么解决

发布时间:2020-02-04  |  点击率:

workerman+tp5的错误问题怎么解决?thinkphp5+workerman 报错问题

在thinkphp5.0.X版本早期会遇到长时间开启workerman服务会报错,在thinkphp5.0.24版本已经修复。原因是因为长时间链接数据库,导致数据库断线。

推荐:《Workerman教程

解决的方案:

1、修改数据库配置database.php文件,将break_reconnect参数设置为true。断线重连。

// 是否需要断线重连
'break_reconnect' => true,

2、修改 /library/think/db/Connection.php中的isBreak函数,替换为以下最新的isBreak函数。

  /**
     * 是否断线
     * @access protected
     * @param \PDOException|\Exception  $e 异常对象
     * @return bool
     */
    protected function isBreak($e)
    {
        if (!$this->config['break_reconnect']) {
            return false;
        }
 
        $info = [
            'server has gone away',
            'no connection to the server',
            'Lost connection',
            'is dead or not enabled',
            'Error while sending',
            'decryption failed or bad record mac',
            'server closed the connection unexpectedly',
            'SSL connection has been closed unexpectedly',
            'Error writing data to the connection',
            'Resource deadlock avoided',
            'failed with errno',
        ];
 
        $error = $e->getMessage();
 
        foreach ($info as $msg) {
            if (false !== stripos($error, $msg)) {
                return true;
            }
        }
        return false;
    }

3、将/library/think/db/connector/Mysql.php中的isBreak函数删除或者注释掉。

修改完后,workerman长时间链接数据库,数据库断开会重连。

全国统一服务电话

400 890 5375

电子邮箱:879577@qq.com

公司地址:宜昌市西陵区黄河路5号三峡明珠10栋1051室

咨询微信

TEL:13680874598