Browse Source

调试能通了,Db能用了

lizhen_gitee 3 years ago
parent
commit
3a04878099

+ 31 - 42
application/chat/Events.php

@@ -25,59 +25,48 @@
  */
 //use \GatewayWorker\Lib\Gateway;
 //use \GatewayWorker\Lib\DbConnection;
-use \think\Db;
+use think\Db;
+use think\App;
 
 class Events
 {
 
     public static function onWorkerStart(){
 
-        /*global $db;
-        $my_config = array(
-            'host'     => '127.0.0.1',
-            'port'     => '3306',
-            'user'     => 'youeryuan',
-            'password' => 'XwXXAFbp8kaYsLKF',
-            'dbname'   => 'youeryuan',
-            'charset'  => 'utf8',
-        );
-        $db = new DbConnection($my_config);*/
-
-        echo 'onWorkerStart';
-
+        App::initCommon();
 
+        /*$info = Db::name('mt_admin')->find(1);
+        dump($info);*/
 
     }
-   
-   /**
-    * 有消息时
-    * @param int $client_id
-    * @param mixed $message
-    */
-   public static function onMessage($client_id, $message)
-   {
-        dump($message);
-       file_put_contents('1.json',$message.PHP_EOL,FILE_APPEND);
-       return ;
 
-   }
+    /**
+     * 有消息时
+     * @param int $client_id
+     * @param mixed $message
+     */
+    public static function onMessage($client_id, $message)
+    {
+        dump($message);
+        return ;
+    }
    
-   /**
-    * 当客户端断开连接时
-    * @param integer $client_id 客户端id
-    */
-   public static function onClose($client_id)
-   {
-       // debug
-      /* echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']}  client_id:$client_id onClose:''\n";
+    /**
+     * 当客户端断开连接时
+     * @param integer $client_id 客户端id
+     */
+    public static function onClose($client_id)
+    {
+        // debug
+        /* echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']}  client_id:$client_id onClose:''\n";
        
-       // 从房间的客户端列表中删除
-       if(isset($_SESSION['room_id']))
-       {
-           $room_id = $_SESSION['room_id'];
-           $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s'));
-           Gateway::sendToGroup($room_id, json_encode($new_message));
-       }*/
-   }
+         // 从房间的客户端列表中删除
+         if(isset($_SESSION['room_id']))
+         {
+             $room_id = $_SESSION['room_id'];
+             $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s'));
+             Gateway::sendToGroup($room_id, json_encode($new_message));
+         }*/
+    }
   
 }

+ 1 - 1
application/chat/start_businessworker.php

@@ -15,7 +15,7 @@ use \Workerman\Worker;
 use \GatewayWorker\BusinessWorker;
 use \Workerman\Autoloader;
 
-require_once __DIR__ . '/../../vendor/autoload.php';
+//require_once __DIR__ . '/../../vendor/autoload.php';
 
 // bussinessWorker 进程
 $worker = new BusinessWorker();

+ 1 - 1
application/chat/start_gateway.php

@@ -15,7 +15,7 @@ use \Workerman\Worker;
 use \GatewayWorker\Gateway;
 use \Workerman\Autoloader;
 
-require_once __DIR__ . '/../../vendor/autoload.php';
+//require_once __DIR__ . '/../../vendor/autoload.php';
 
 // gateway 进程
 $gateway = new Gateway("tcp://0.0.0.0:2349");

+ 1 - 1
application/chat/start_register.php

@@ -14,7 +14,7 @@
 use \Workerman\Worker;
 use \GatewayWorker\Register;
 
-require_once __DIR__ . '/../../vendor/autoload.php';
+//require_once __DIR__ . '/../../vendor/autoload.php';
 
 // register 服务必须是text协议
 $register = new Register('text://0.0.0.0:2348');

+ 3 - 3
application/database.php

@@ -15,11 +15,11 @@ return [
     // 服务器地址
     'hostname'        => '1.14.197.70',
     // 数据库名
-    'database'        => 'youeryuan',
+    'database'        => 'mita',
     // 用户名
-    'username'        => 'youeryuan',
+    'username'        => 'mita',
     // 密码
-    'password'        => 'XwXXAFbp8kaYsLKF',
+    'password'        => 'RHNfhbdepaZEHzBH',
     // 端口
     'hostport'        => '',
     // 连接dsn

+ 17 - 7
newone.php

@@ -7,6 +7,10 @@
 ini_set('display_errors', 'on');
 use Workerman\Worker;
 
+//重定向目录
+$cur_dir = dirname(__FILE__);
+chdir($cur_dir);
+
 if(strpos(strtolower(PHP_OS), 'win') === 0)
 {
     exit("start.php not support windows, please use start_for_win.bat\n");
@@ -25,17 +29,23 @@ if(!extension_loaded('posix'))
 
 // 标记是全局启动
 define('GLOBAL_START', 1);
+ini_set('memory_limit', '10000M');
 
-require_once __DIR__ . '/vendor/autoload.php';
+/*
+由于TP5自带composer库的加载器.
+如果直接使用vendor的autoload会导致函数重定义错误
+所以直接从入口处引入tp文件,即可加载workerman
+*/
+define('APP_PATH', __DIR__.'/application/');
+require __DIR__.'/thinkphp/base.php';
 
-// 加载所有Applications/*/start.php,以便启动所有服务
+//require_once __DIR__ . '/vendor/autoload.php';
 
-require_once __DIR__.'/applications/chat/start_businessworker.php';
-require_once __DIR__.'/applications/chat/start_gateway.php';
-require_once __DIR__.'/applications/chat/start_register.php';
+// 加载所有Applications/*/start.php,以便启动所有服务
 
-/*define('APP_PATH', __DIR__.'/application/');
-require __DIR__.'/thinkphp/base.php';*/
+require_once __DIR__.'/application/chat/start_businessworker.php';
+require_once __DIR__.'/application/chat/start_gateway.php';
+require_once __DIR__.'/application/chat/start_register.php';
 
 // 运行所有服务
 Worker::runAll();