ThinkPHP5.0.*版本 cli模式下php每隔段时间就出错

关于ThinkPHP5.0.*版本 cli模式下php每隔段时间就出错
cli模式下php每隔段时间就出错
官方论坛
日志如下:

控制台

Uncaught thinkexceptionErrorException: Error while sending STMT_CLOSE packet. PID=23951 in /www/web/work/public_html/thinkphp/library/think/db/Connection.php:318

log文件

thinkdbConnection::free(): send of 9 bytes failed with errno=32 Broken pipe

分析原因

长时间数据库会断线 但是新版本会改进断线重连机制

解决方案

1.临时解决

修改/thinkphp/library/think/db/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;

}

2.官方推荐使用最新版本以解决此问题


作者:HD2killers
来源:CSDN
原文:https://blog.csdn.net/HD2kill...
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值