Bläddra i källkod

Merge branch 'master' into fix-20210309

walkor 4 år sedan
förälder
incheckning
85da6b2ce0
4 ändrade filer med 27 tillägg och 32 borttagningar
  1. 3 2
      Events/Select.php
  2. 4 0
      Protocols/Http.php
  3. 3 3
      Protocols/Http/Request.php
  4. 17 27
      Worker.php

+ 3 - 2
Events/Select.php

@@ -261,9 +261,10 @@ class Select implements EventInterface
                 \pcntl_signal_dispatch();
             }
 
-            $read  = $this->_readFds;
-            $write = $this->_writeFds;
+            $read   = $this->_readFds;
+            $write  = $this->_writeFds;
             $except = $this->_exceptFds;
+            $ret    = false;
 
             if ($read || $write || $except) {
                 // Waiting read/write/signal/timeout events.

+ 4 - 0
Protocols/Http.php

@@ -145,6 +145,10 @@ class Http
                     unset($input[key($input)]);
                 }
             }
+            if ($length > $connection->maxPackageSize) {
+                $connection->close("HTTP/1.1 413 Request Entity Too Large\r\n\r\n");
+                return 0;
+            }
             return $length;
         }
 

+ 3 - 3
Protocols/Http/Request.php

@@ -139,7 +139,7 @@ class Request
      *
      * @param string|null $name
      * @param mixed|null $default
-     * @return string|null
+     * @return array|string|null
      */
     public function header($name = null, $default = null)
     {
@@ -158,7 +158,7 @@ class Request
      *
      * @param string|null $name
      * @param mixed|null $default
-     * @return string|null
+     * @return array|string|null
      */
     public function cookie($name = null, $default = null)
     {
@@ -204,7 +204,7 @@ class Request
     /**
      * Get http protocol version.
      *
-     * @return string.
+     * @return string
      */
     public function protocolVersion()
     {

+ 17 - 27
Worker.php

@@ -598,7 +598,6 @@ class Worker
 
         // For statistics.
         static::$_globalStatistics['start_timestamp'] = \time();
-        static::$_statisticsFile                      = \sys_get_temp_dir() . "/$unique_prefix.status";
 
         // Process title.
         static::setProcessTitle(static::$processTitle . ': master process  start_file=' . static::$_startFile);
@@ -645,6 +644,7 @@ class Worker
         if (static::$_OS !== \OS_TYPE_LINUX) {
             return;
         }
+        static::$_statisticsFile = \sys_get_temp_dir() . "/".posix_getpid().".status";
         foreach (static::$_workers as $worker) {
             // Worker name.
             if (empty($worker->name)) {
@@ -920,6 +920,8 @@ class Worker
             exit;
         }
 
+        $statistics_file = \sys_get_temp_dir() . "/".$master_pid.".status";;
+
         // execute command.
         switch ($command) {
             case 'start':
@@ -929,8 +931,8 @@ class Worker
                 break;
             case 'status':
                 while (1) {
-                    if (\is_file(static::$_statisticsFile)) {
-                        @\unlink(static::$_statisticsFile);
+                    if (\is_file($statistics_file)) {
+                        @\unlink($statistics_file);
                     }
                     // Master process will send SIGUSR2 signal to all child processes.
                     \posix_kill($master_pid, SIGUSR2);
@@ -941,7 +943,7 @@ class Worker
                         static::safeEcho("\33[H\33[2J\33(B\33[m", true);
                     }
                     // Echo status data.
-                    static::safeEcho(static::formatStatusData());
+                    static::safeEcho(static::formatStatusData($statistics_file));
                     if ($mode !== '-d') {
                         exit(0);
                     }
@@ -949,16 +951,16 @@ class Worker
                 }
                 exit(0);
             case 'connections':
-                if (\is_file(static::$_statisticsFile) && \is_writable(static::$_statisticsFile)) {
-                    \unlink(static::$_statisticsFile);
+                if (\is_file($statistics_file) && \is_writable($statistics_file)) {
+                    \unlink($statistics_file);
                 }
                 // Master process will send SIGIO signal to all child processes.
                 \posix_kill($master_pid, SIGIO);
                 // Waiting amoment.
                 \usleep(500000);
                 // Display statisitcs data from a disk file.
-                if(\is_readable(static::$_statisticsFile)) {
-                    \readfile(static::$_statisticsFile);
+                if(\is_readable($statistics_file)) {
+                    \readfile($statistics_file);
                 }
                 exit(0);
             case 'restart':
@@ -1020,15 +1022,16 @@ class Worker
     /**
      * Format status data.
      *
+     * @param $statistics_file
      * @return string
      */
-    protected static function formatStatusData()
+    protected static function formatStatusData($statistics_file)
     {
         static $total_request_cache = array();
-        if (!\is_readable(static::$_statisticsFile)) {
+        if (!\is_readable($statistics_file)) {
             return '';
         }
-        $info = \file(static::$_statisticsFile, \FILE_IGNORE_NEW_LINES);
+        $info = \file($statistics_file, \FILE_IGNORE_NEW_LINES);
         if (!$info) {
             return '';
         }
@@ -1310,23 +1313,9 @@ class Worker
         }
 
         if ($loop_name) {
-            if (\interface_exists('\React\EventLoop\LoopInterface')) {
-                switch ($loop_name) {
-                    case 'libevent':
-                        static::$eventLoopClass = '\Workerman\Events\React\ExtLibEventLoop';
-                        break;
-                    case 'event':
-                        static::$eventLoopClass = '\Workerman\Events\React\ExtEventLoop';
-                        break;
-                    default :
-                        static::$eventLoopClass = '\Workerman\Events\React\StreamSelectLoop';
-                        break;
-                }
-            } else {
-                static::$eventLoopClass = static::$_availableEventLoops[$loop_name];
-            }
+            static::$eventLoopClass = static::$_availableEventLoops[$loop_name];
         } else {
-            static::$eventLoopClass = \interface_exists('\React\EventLoop\LoopInterface') ? '\Workerman\Events\React\StreamSelectLoop' : '\Workerman\Events\Select';
+            static::$eventLoopClass =  '\Workerman\Events\Select';
         }
         return static::$eventLoopClass;
     }
@@ -2591,3 +2580,4 @@ class Worker
         return stripos($content, static::$processTitle) !== false;
     }
 }
+