(thinkphp)Error while sending STMT_PREPARE packet. PID=某些数字

这个错误有时候执行程序就会突然出现,比较不稳定。。。想调试也无从下手。我这边是通过频繁刷新大概7-20次,就会出现这个错误了,然后去ThinkPHP官网论坛找了相关资料整理出方法:

thinkphp5.0.x版本有这问题,thinkphp5.0.24版本已经修复

1、修改数据库设置文件 database.php或者config.php添加

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

修改第一步之后,我频繁刷新都不会出现那个错误了。但网上资料说要把以下两步也改改,改不改看个人情况吧:

2、修改 /thinkphp/library/think/db/Connection.php的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;
    }

直接替换函数

3、找找/thinkphp/library/think/db/connector/Mysql.php中是否也有isBreak函数,如果有就注释或删掉。

你可能感兴趣的:(php,thinkphp)