作者 邓超

x

@@ -66,7 +66,10 @@ class DbPool { @@ -66,7 +66,10 @@ class DbPool {
66 */ 66 */
67 public function connect(){ 67 public function connect(){
68 $this->lastTimer = time(); 68 $this->lastTimer = time();
69 -// try { 69 + $tryNum = 0;
  70 +
  71 + DBPOOLCONNECTFOR:
  72 + try {
70 $this->client = new \PDO( 73 $this->client = new \PDO(
71 'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT, 74 'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT,
72 DB_USER, 75 DB_USER,
@@ -77,9 +80,18 @@ class DbPool { @@ -77,9 +80,18 @@ class DbPool {
77 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, 80 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
78 ] 81 ]
79 ); 82 );
80 -// }catch (\Throwable $e){  
81 -// logs($e->getMessage().$e->getTraceAsString());  
82 -// } 83 + }catch (\Throwable $e){
  84 + // 重新链接3次
  85 + if($tryNum < 3){
  86 + $tryNum++;
  87 + goto DBPOOLCONNECTFOR;
  88 + }
  89 +
  90 + logs($e->getMessage().$e->getTraceAsString());
  91 + }
  92 +
  93 +
  94 +
83 } 95 }
84 96
85 97