栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

Error while sending STMT_PREPARE packet. PID=18017用法

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力


image.png

这个报错是长时间连接数据库会断线,导致这个原因有多种可能,最有可能是:

1、大批量对数据库增删改;

2、增删改是因服务器卡;

3、其他可能性,未知;


第一步:修改数据库配置文件 database.php ,设置为true,开启断线重连;

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

第二步:修改 /library/think/db/Connection.php中的isBreak函数,替换为以下最新的isBreak函数:

    
    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;
    }

第三步:注释 /library/think/db/connector/Mysql.php中的isBreak函数

protected function isBreak($e)
{
    if (!$this->config['break_reconnect']) {
        return false;
    }

    $error = $e->getMessage();

    foreach ($this->breakMatchStr as $msg) {
        if (false !== stripos($error, $msg)) {
            return true;
        }
    }
    return false;
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/824805.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号