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

版权声明: https://blog.csdn.net/weixin_41728561/article/details/85840331

使用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

再次提交,成功

猜你喜欢

转载自blog.csdn.net/weixin_41728561/article/details/85840331
PID