使用版本:TP5.1、 thinkphp-queue 2.0
mysql超时断线问题
队列任务运行一段时间,出现:SQLSTATE[HY000]: General error: 2006 MySQL server has gone away报错。
解决方法和分析:
配置文件database.php中配置断线重连:
// 是否需要断线重连
'break_reconnect' => true,
// 断线标识字符串
'break_match_str' => ['2006'],
配置后虽然日志中会出现另一个报错:PDO::prepare(): send of 60 bytes failed with errno=32 Broken pipe,但并不影响程序运行结果。因为断线重连后,程序都会抛出错误:
.
.
.
} catch (\PDOException $e) {
if ($this->isBreak($e)) {
return $this->close()->query($sql, $bind, $master, $pdo);
}
throw new PDOException($e, $this->config, $this->getLastsql());
} catch (\Throwable $e) {
if ($this->isBreak($e)) {
return $this->cl