Przeglądaj źródła

Update Controller.php

aiden3434 7 lat temu
rodzic
commit
3680b5b075
1 zmienionych plików z 16 dodań i 0 usunięć
  1. 16 0
      app/Http/Controllers/Controller.php

+ 16 - 0
app/Http/Controllers/Controller.php

@@ -103,6 +103,22 @@ class Controller extends BaseController
 
         return $port;
     }
+    
+    // 获取一个端口
+    public function getOnlyPort()
+    {
+        $config = $this->systemConfig();
+
+        $port = $config['min_port'];
+        $deny_port = [1068, 1109, 1434, 3127, 3128, 3129, 3130, 3332, 4444, 5554, 6669, 8080, 8081, 8082, 8181, 8282, 9996, 17185, 24554, 35601, 60177, 60179]; // 不生成的端口
+
+        $exists_port = User::query()->where('port', '>=', $config['min_port'])->where('port', '<=', $config['max_port'])->pluck('port')->toArray();
+        while (in_array($port, $exists_port) || in_array($port, $deny_port)) {
+            $port = $port + 1;
+        }
+
+        return $port;
+    }
 
     // 类似Linux中的tail命令
     public function tail($file, $n, $base = 5)