diff --git a/composer.json b/composer.json index 969fc952..fc500929 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "high-performance intelligent assistant", "minimum-stability": "stable", "license": "Apache-2.0", - "version": "1.4.0", + "version": "1.4.1", "authors": [ { "name": "whale", diff --git a/src/ZM/DB/DB.php b/src/ZM/DB/DB.php index 6084e9de..67fc6253 100644 --- a/src/ZM/DB/DB.php +++ b/src/ZM/DB/DB.php @@ -7,6 +7,7 @@ namespace ZM\DB; use Exception; use framework\Console; use framework\ZMBuf; +use PDOException; use PDOStatement; use Swoole\Coroutine; use Swoole\Database\PDOStatementProxy; @@ -132,7 +133,7 @@ class DB } return $ps->fetchAll(); } - } catch (DBException $e) { + } catch (DbException $e) { if (ZMBuf::get("sql_log") === true) { $log = "[" . date("Y-m-d H:i:s") . @@ -147,6 +148,21 @@ class DB } Console::warning($e->getMessage()); throw $e; + } catch (PDOException $e) { + if (ZMBuf::get("sql_log") === true) { + $log = + "[" . date("Y-m-d H:i:s") . + " " . round(microtime(true) - $starttime, 4) . + "] " . $line . " " . json_encode($params, JSON_UNESCAPED_UNICODE) . " (Error:" . $e->getMessage() . ")\n"; + Coroutine::writeFile(CRASH_DIR . "sql.log", $log, FILE_APPEND); + } + if(mb_strpos($e->getMessage(), "has gone away") !== false) { + zm_sleep(0.2); + Console::warning("Gone away of MySQL! retrying!"); + return self::rawQuery($line, $params); + } + Console::warning($e->getMessage()); + throw new DbException($e->getMessage(), $e->getCode(), $e); } }