lizhen_gitee hace 1 año
padre
commit
7495fdceb7

+ 2 - 1
vendor/workerman/gateway-worker/src/BusinessWorker.php

@@ -12,7 +12,8 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace GatewayWorker;
-
+require_once __DIR__.'/../../workerman/Worker.php';
+require_once __DIR__.'/Lib/Gateway.php';
 use Workerman\Connection\TcpConnection;
 
 use Workerman\Worker;

+ 3 - 15
vendor/workerman/gateway-worker/src/Gateway.php

@@ -12,7 +12,7 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace GatewayWorker;
-
+require_once __DIR__.'/Protocols/GatewayProtocol.php';
 use GatewayWorker\Lib\Context;
 
 use Workerman\Connection\TcpConnection;
@@ -575,13 +575,7 @@ class Gateway extends Worker
             // 向某客户端发送数据,Gateway::sendToClient($client_id, $message);
             case GatewayProtocol::CMD_SEND_TO_ONE:
                 if (isset($this->_clientConnections[$data['connection_id']])) {
-                    $raw = (bool)($data['flag'] & GatewayProtocol::FLAG_NOT_CALL_ENCODE);
-                    $body = $data['body'];
-                    if (!$raw && $this->protocolAccelerate && $this->protocol) {
-                        $body = $this->preEncodeForClient($body);
-                        $raw = true;
-                    }
-                    $this->_clientConnections[$data['connection_id']]->send($body, $raw);
+                    $this->_clientConnections[$data['connection_id']]->send($data['body']);
                 }
                 return;
             // 踢出用户,Gateway::closeClient($client_id, $message);
@@ -772,18 +766,12 @@ class Gateway extends Worker
                 return;
             // 发送数据给 uid Gateway::sendToUid($uid, $msg);
             case GatewayProtocol::CMD_SEND_TO_UID:
-                $raw = (bool)($data['flag'] & GatewayProtocol::FLAG_NOT_CALL_ENCODE);
-                $body = $data['body'];
-                if (!$raw && $this->protocolAccelerate && $this->protocol) {
-                    $body = $this->preEncodeForClient($body);
-                    $raw = true;
-                }
                 $uid_array = json_decode($data['ext_data'], true);
                 foreach ($uid_array as $uid) {
                     if (!empty($this->_uidConnections[$uid])) {
                         foreach ($this->_uidConnections[$uid] as $connection) {
                             /** @var TcpConnection $connection */
-                            $connection->send($body, $raw);
+                            $connection->send($data['body']);
                         }
                     }
                 }

+ 4 - 3
vendor/workerman/gateway-worker/src/Lib/DbConnection.php

@@ -1682,16 +1682,17 @@ class DbConnection
      * @param string $db_name
      * @param string $charset
      */
-    public function __construct($host, $port, $user, $password, $db_name, $charset = 'utf8')
+    public function __construct($config)
     {
-        $this->settings = array(
+        /*$this->settings = array(
             'host'     => $host,
             'port'     => $port,
             'user'     => $user,
             'password' => $password,
             'dbname'   => $db_name,
             'charset'  => $charset,
-        );
+        );*/
+        $this->settings = $config;
         $this->connect();
     }
 

+ 18 - 28
vendor/workerman/gateway-worker/src/Lib/Gateway.php

@@ -137,26 +137,24 @@ class Gateway
     /**
      * 向某个client_id对应的连接发消息
      *
-     * @param string    $client_id
+     * @param int    $client_id
      * @param string $message
-     * @param bool $raw
      * @return void
      */
-    public static function sendToClient($client_id, $message, $raw = false)
+    public static function sendToClient($client_id, $message)
     {
-        return static::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_SEND_TO_ONE, $message, $raw);
+        return static::sendCmdAndMessageToClient($client_id, GatewayProtocol::CMD_SEND_TO_ONE, $message);
     }
 
     /**
      * 向当前客户端连接发送消息
      *
      * @param string $message
-     * @param bool $raw
      * @return bool
      */
-    public static function sendToCurrentClient($message, $raw = false)
+    public static function sendToCurrentClient($message)
     {
-        return static::sendCmdAndMessageToClient(null, GatewayProtocol::CMD_SEND_TO_ONE, $message, $raw);
+        return static::sendCmdAndMessageToClient(null, GatewayProtocol::CMD_SEND_TO_ONE, $message);
     }
 
     /**
@@ -173,7 +171,7 @@ class Gateway
     /**
      * 判断client_id对应的连接是否在线
      *
-     * @param string $client_id
+     * @param int $client_id
      * @return int 0|1
      */
     public static function isOnline($client_id)
@@ -839,7 +837,7 @@ class Gateway
     /**
      * 踢掉某个客户端并直接立即销毁相关连接
      *
-     * @param string $client_id
+     * @param int $client_id
      * @return bool
      */
     public static function destoryClient($client_id)
@@ -875,7 +873,7 @@ class Gateway
     /**
      * 将 client_id 与 uid 绑定
      *
-     * @param string        $client_id
+     * @param int        $client_id
      * @param int|string $uid
      * @return void
      */
@@ -887,7 +885,7 @@ class Gateway
     /**
      * 将 client_id 与 uid 解除绑定
      *
-     * @param string        $client_id
+     * @param int        $client_id
      * @param int|string $uid
      * @return void
      */
@@ -899,7 +897,7 @@ class Gateway
     /**
      * 将 client_id 加入组
      *
-     * @param string        $client_id
+     * @param int        $client_id
      * @param int|string $group
      * @return void
      */
@@ -912,7 +910,7 @@ class Gateway
     /**
      * 将 client_id 离开组
      *
-     * @param string        $client_id
+     * @param int        $client_id
      * @param int|string $group
      *
      * @return void
@@ -946,18 +944,14 @@ class Gateway
      *
      * @param int|string|array $uid
      * @param string           $message
-     * @param bool $raw
      *
      * @return void
      */
-    public static function sendToUid($uid, $message, $raw = false)
+    public static function sendToUid($uid, $message)
     {
         $gateway_data         = GatewayProtocol::$empty;
         $gateway_data['cmd']  = GatewayProtocol::CMD_SEND_TO_UID;
         $gateway_data['body'] = $message;
-        if ($raw) {
-            $gateway_data['flag'] |= GatewayProtocol::FLAG_NOT_CALL_ENCODE;
-        }
 
         if (!is_array($uid)) {
             $uid = array($uid);
@@ -1031,7 +1025,7 @@ class Gateway
     /**
      * 更新 session,框架自动调用,开发者不要调用
      *
-     * @param string    $client_id
+     * @param int    $client_id
      * @param string $session_str
      * @return bool
      */
@@ -1043,7 +1037,7 @@ class Gateway
     /**
      * 设置 session,原session值会被覆盖
      *
-     * @param string   $client_id
+     * @param int   $client_id
      * @param array $session
      *
      * @return void
@@ -1060,7 +1054,7 @@ class Gateway
     /**
      * 更新 session,实际上是与老的session合并
      *
-     * @param string   $client_id
+     * @param int   $client_id
      * @param array $session
      *
      * @return void
@@ -1077,7 +1071,7 @@ class Gateway
     /**
      * 获取某个client_id的session
      *
-     * @param string   $client_id
+     * @param int   $client_id
      * @return mixed false表示出错、null表示用户不存在、array表示具体的session信息 
      */
     public static function getSession($client_id)
@@ -1101,14 +1095,13 @@ class Gateway
     /**
      * 向某个用户网关发送命令和消息
      *
-     * @param string    $client_id
+     * @param int    $client_id
      * @param int    $cmd
      * @param string $message
      * @param string $ext_data
-     * @param bool $raw
      * @return boolean
      */
-    protected static function sendCmdAndMessageToClient($client_id, $cmd, $message, $ext_data = '', $raw = false)
+    protected static function sendCmdAndMessageToClient($client_id, $cmd, $message, $ext_data = '')
     {
         // 如果是发给当前用户则直接获取上下文中的地址
         if ($client_id === Context::$client_id || $client_id === null) {
@@ -1129,9 +1122,6 @@ class Gateway
         if (!empty($ext_data)) {
             $gateway_data['ext_data'] = $ext_data;
         }
-        if ($raw) {
-            $gateway_data['flag'] |= GatewayProtocol::FLAG_NOT_CALL_ENCODE;
-        }
 
         return static::sendToGateway($address, $gateway_data);
     }

+ 1 - 1
vendor/workerman/gatewayclient/Gateway.php

@@ -36,7 +36,7 @@ class Gateway
      *
      * @var string|array
      */
-    public static $registerAddress = '127.0.0.1:1236';
+    public static $registerAddress = '127.0.0.1:2345';
 
     /**
      * 秘钥

+ 1 - 5
vendor/workerman/workerman/Events/Swoole.php

@@ -61,11 +61,7 @@ class Swoole implements EventInterface
                     $this->mapId = 0;
                 }
                 $mapId = $this->mapId++;
-                $t = (int)($fd * 1000);
-                if ($t < 1) {
-                   $t = 1;   
-                }
-                $timer_id = Timer::$method($t,
+                $timer_id = Timer::$method($fd * 1000,
                     function ($timer_id = null) use ($func, $args, $mapId) {
                         \call_user_func_array($func, $args);
                         // EV_TIMER_ONCE

+ 4 - 23
vendor/workerman/workerman/Protocols/Http/Request.php

@@ -392,11 +392,7 @@ class Request
     {
         $this->_data['headers'] = array();
         $raw_head = $this->rawHead();
-        $end_line_position = \strpos($raw_head, "\r\n");
-        if ($end_line_position === false) {
-            return;
-        }
-        $head_buffer = \substr($raw_head, $end_line_position + 2);
+        $head_buffer = \substr($raw_head, \strpos($raw_head, "\r\n") + 2);
         $cacheable = static::$_enableCache && !isset($head_buffer[2048]);
         if ($cacheable && isset(static::$_headerCache[$head_buffer])) {
             $this->_data['headers'] = static::$_headerCache[$head_buffer];
@@ -406,16 +402,9 @@ class Request
         foreach ($head_data as $content) {
             if (false !== \strpos($content, ':')) {
                 list($key, $value) = \explode(':', $content, 2);
-                $key = \strtolower($key);
-                $value = \ltrim($value);
+                $this->_data['headers'][\strtolower($key)] = \ltrim($value);
             } else {
-                $key = \strtolower($content);
-                $value = '';
-            }
-            if (isset($this->_data['headers'][$key])) {
-                $this->_data['headers'][$key] = "{$this->_data['headers'][$key]},$value";
-            } else {
-                $this->_data['headers'][$key] = $value;
+                $this->_data['headers'][\strtolower($content)] = '';
             }
         }
         if ($cacheable) {
@@ -515,7 +504,7 @@ class Request
                 switch ($header_key) {
                     case "content-disposition":
                         // Is file data.
-                        if (\preg_match('/name="(.*?)"; filename="(.*?)"/i', $header_value, $match)) {
+                        if (\preg_match('/name="(.*?)"; filename="(.*?)"$/i', $header_value, $match)) {
                             $error = 0;
                             $tmp_file = '';
                             $size = \strlen($boundary_value);
@@ -616,14 +605,6 @@ class Request
     }
 
     /**
-     * __toString.
-     */
-    public function __toString()
-    {
-        return $this->_buffer;
-    }
-
-    /**
      * __destruct.
      *
      * @return void

+ 1 - 1
vendor/workerman/workerman/README.md

@@ -77,7 +77,7 @@ $http_worker->onMessage = function ($connection, $request) {
     //$request->post();
     //$request->header();
     //$request->cookie();
-    //$request->session();
+    //$requset->session();
     //$request->uri();
     //$request->path();
     //$request->method();

+ 5 - 35
vendor/workerman/workerman/Worker.php

@@ -33,7 +33,7 @@ class Worker
      *
      * @var string
      */
-    const VERSION = '4.0.19';
+    const VERSION = '4.0.18';
 
     /**
      * Status starting.
@@ -909,8 +909,9 @@ class Worker
 
         // Get master process PID.
         $master_pid      = \is_file(static::$pidFile) ? \file_get_contents(static::$pidFile) : 0;
+        $master_is_alive = $master_pid && \posix_kill($master_pid, 0) && \posix_getpid() !== $master_pid;
         // Master is still alive?
-        if (static::checkMasterIsAlive($master_pid)) {
+        if ($master_is_alive) {
             if ($command === 'start') {
                 static::log("Workerman[$start_file] already running");
                 exit;
@@ -2213,14 +2214,13 @@ class Worker
         }
 
         // Turn reusePort on.
-        /*if (static::$_OS === \OS_TYPE_LINUX  // if linux
+        if (static::$_OS === \OS_TYPE_LINUX  // if linux
             && \version_compare(\PHP_VERSION,'7.0.0', 'ge') // if php >= 7.0.0
-            && \version_compare(php_uname('r'), '3.9', 'ge') // if kernel >=3.9
             && \strtolower(\php_uname('s')) !== 'darwin' // if not Mac OS
             && strpos($socket_name,'unix') !== 0) { // if not unix socket
 
             $this->reusePort = true;
-        }*/
+        }
     }
 
 
@@ -2560,34 +2560,4 @@ class Worker
         }
         return true;
     }
-
-    /**
-     * Check master process is alive
-     *
-     * @param $master_pid
-     * @return bool
-     */
-    protected static function checkMasterIsAlive($master_pid)
-    {
-        if (empty($master_pid)) {
-            return false;
-        }
-
-        $master_is_alive = $master_pid && \posix_kill($master_pid, 0) && \posix_getpid() !== $master_pid;
-        if (!$master_is_alive) {
-            return false;
-        }
-
-        $cmdline = "/proc/{$master_pid}/cmdline";
-        if (!is_readable($cmdline) || empty(static::$processTitle)) {
-            return true;
-        }
-
-        $content = file_get_contents($cmdline);
-        if (empty($content)) {
-            return true;
-        }
-
-        return stripos($content, static::$processTitle) !== false;
-    }
 }