ThinkPHP5.0.*版本 cli模式下php每隔段時間就出錯

關於ThinkPHP5.0.*版本 cli模式下php每隔段時間就出錯
cli模式下php每隔段時間就出錯
官方論壇
日誌以下:php

控制檯

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

log文件

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

分析緣由web

長時間數據庫會斷線 可是新版本會改進斷線重連機制

解決方案sql

1.臨時解決

修改/thinkphp/library/think/db/Connection.php

1.1是否須要斷線重連

'break_reconnect' => true,thinkphp

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

}ide

1.3 是否斷線,修改成master最新

protected function isBreak($e)
{this

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;

}.net

2.官方推薦使用最新版本以解決此問題


做者:HD2killers
來源:CSDN
原文:https://blog.csdn.net/HD2kill... 版權聲明:本文爲博主原創文章,轉載請附上博文連接!

相關文章
相關標籤/搜索