【ThinkPHP】'Error while sending STMT_CLOSE packet. PID think\db\Connection->free()

使用ThinkPHP上传内容  

较少的内容可以上传成功

多的内容就上传失败

报错信息:

'Error while sending STMT_CLOSE packet. PID  think\db\Connection->free()(重点就是这两句)

错误地址指向Connection.php的free()方法

解决办法:

将Connection.php的相关内容修改为以下的内容

# 1.1是否需要断线重连
'break_reconnect' => true,
# 1.2 释放查询结果 捕获异常
public function free()
{
    try {
        $this->PDOStatement = null;
    } catch (Exception $e) {
        Log::write("has error when free PDOStatement maybe mysql gone away,skip it:" . $e->getMessage(), log::DEBUG);
    }
}
# 1.3 是否断线,修改为master最新
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',
        'send of 33 bytes failed with errno=32 Broken pipe',
    ];

    $error = $e->getMessage();

    foreach ($info as $msg) {
        if (false !== stripos($error, $msg)) {
            return true;
        }
    }
    return false;
}

参考于:https://blog.csdn.net/HD2killers/article/details/83744285

再次提交,又报错了

错误信息:

Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes

解决办法:

打开数据库

show VARIABLES like '%max_allowed_packet%'

我的结果是1024

太小了

修改

set global max_allowed_packet = 1048576*10;

退出

重新打开

mysql> show VARIABLES like '%max_allowed_packet%'
;
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| max_allowed_packet       | 10485760 |
| slave_max_allowed_packet | 20971520 |
+--------------------------+----------+
2 rows in set

再次提交,成功

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值