我用ESD框架
他有个mysql插件,插件内获取mysql实例是用连接池的:
public function mysql($name = "default")
{
$db = getContextValue("MysqliDb:$name");
if ($db == null) {
/** @var MysqlManyPool $mysqlPool */
$mysqlPool = getDeepContextValueByClassName(MysqlManyPool::class);
$pool = $mysqlPool->getPool($name);
if ($pool == null) throw new MysqlException("No MySQL connection pool named {$name} was found");
return $pool->db();
} else {
return $db;
}
}
由于程序是常驻内存的,mysql的连接实例也在内存中的,但是因为mysql的连接是会因为超过 wait_timeou 设置而断开的。所以当断开后程序再次使用内存中的msyql实例时。就会报如下错误:
PHP Warning: mysqli::prepare(): MySQL server has gone away in /data/wwwroot/xunim/vendor/esd/mysql-plugin/src/Mysql/Mysqli.php on line 39
请问各位大神,你们有什么好办法解决?
框架应该提供类似 2006,2013 错误时自动重连并重新执行的功能
如果没有提供就只有自己写 try catch 判断并处理,参考:
https://github.com/tsingsun/y...