瀏覽代碼

测试修改

lizhen_gitee 1 年之前
父節點
當前提交
c41ae7d42a
共有 4 個文件被更改,包括 30 次插入5 次删除
  1. 15 2
      application/chat/Events.php
  2. 2 0
      application/database.php
  3. 1 1
      restart.sh
  4. 12 2
      thinkphp/library/think/db/Connection.php

+ 15 - 2
application/chat/Events.php

@@ -55,9 +55,9 @@ class Events
          if(is_array($message)){
              self::changestatus($message);
          }else{
-             echo 'default';
+             //echo 'default';
          }
-         return ;
+         //return ;
 
          /*if(is_array($message) && isset($message['action']) && $message['action'] == 'changestatus'){
              self::changestatus($message);
@@ -67,6 +67,19 @@ class Events
          return ;*/
     }
 
+    /**
+     * 当客户端连接时触发
+     * 如果业务不需此回调可以删除onConnect
+     * @param int $client_id 连接id
+     */
+    /*public static function onConnect($client_id)
+    {
+        // 向当前client_id发送数据
+        Gateway::sendToClient($client_id, "Hello $client_id");
+        // 向所有人发送
+        Gateway::sendToAll("$client_id login");
+    }*/
+
 
 	/*{
         'action':'changestatus',

+ 2 - 0
application/database.php

@@ -52,4 +52,6 @@ return [
     'datetime_format' => 'Y-m-d H:i:s',
     // 是否需要进行SQL性能分析
     'sql_explain'     => false,
+    // 是否需要断线重连
+    'break_reconnect' => true,
 ];

+ 1 - 1
restart.sh

@@ -1,2 +1,2 @@
 php newone.php stop;
-php newone.php start -d;
+php newone.php start -d;

+ 12 - 2
thinkphp/library/think/db/Connection.php

@@ -109,7 +109,7 @@ abstract class Connection
         // Query类
         'query'           => '\\think\\db\\Query',
         // 是否需要断线重连
-        'break_reconnect' => false,
+        'break_reconnect' => true,
     ];
 
     // PDO连接参数
@@ -313,11 +313,21 @@ abstract class Connection
      * 释放查询结果
      * @access public
      */
-    public function free()
+    public function free_old()
     {
         $this->PDOStatement = null;
     }
 
+    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);
+        }
+    }
+
+
     /**
      * 获取PDO对象
      * @access public