Эх сурвалжийг харах

Merge pull request #775 from twomiao/master

Worker code optimization
walkor 3 жил өмнө
parent
commit
2e0ec339fe

+ 3 - 0
README.md

@@ -270,10 +270,13 @@ Worker::runAll();
 ```php start.php start  ```  
 ```php start.php start  ```  
 ```php start.php start -d  ```  
 ```php start.php start -d  ```  
 ```php start.php status  ```  
 ```php start.php status  ```  
+```php start.php status -d  ```  
 ```php start.php connections```  
 ```php start.php connections```  
 ```php start.php stop  ```  
 ```php start.php stop  ```  
+```php start.php stop -g  ```  
 ```php start.php restart  ```  
 ```php start.php restart  ```  
 ```php start.php reload  ```  
 ```php start.php reload  ```  
+```php start.php reload -g  ```
 
 
 ## Documentation
 ## Documentation
 
 

+ 3 - 3
src/Protocols/Websocket.php

@@ -328,11 +328,11 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
         // HTTP protocol.
         // HTTP protocol.
         if (0 === \strpos($buffer, 'GET')) {
         if (0 === \strpos($buffer, 'GET')) {
             // Find \r\n\r\n.
             // Find \r\n\r\n.
-            $heder_end_pos = \strpos($buffer, "\r\n\r\n");
-            if (!$heder_end_pos) {
+            $header_end_pos = \strpos($buffer, "\r\n\r\n");
+            if (!$header_end_pos) {
                 return 0;
                 return 0;
             }
             }
-            $header_length = $heder_end_pos + 4;
+            $header_length = $header_end_pos + 4;
 
 
             // Get Sec-WebSocket-Key.
             // Get Sec-WebSocket-Key.
             $Sec_WebSocket_Key = '';
             $Sec_WebSocket_Key = '';

+ 4 - 11
src/Worker.php

@@ -1488,7 +1488,7 @@ class Worker
             if (static::$_status === static::STATUS_STARTING) {
             if (static::$_status === static::STATUS_STARTING) {
                 static::resetStd();
                 static::resetStd();
             }
             }
-            static::$_pidMap  = [];
+            static::$_pidsToRestart = static::$_pidMap  = [];
             // Remove other listener.
             // Remove other listener.
             foreach(static::$_workers as $key => $one_worker) {
             foreach(static::$_workers as $key => $one_worker) {
                 if ($one_worker->workerId !== $worker->workerId) {
                 if ($one_worker->workerId !== $worker->workerId) {
@@ -1708,11 +1708,7 @@ class Worker
                 }
                 }
             }
             }
 
 
-            if (static::$_gracefulStop) {
-                $sig = \SIGUSR2;
-            } else {
-                $sig = \SIGUSR1;
-            }
+            $sig = static::$_gracefulStop ? \SIGUSR2 : \SIGUSR1;
 
 
             // Send reload signal to all child processes.
             // Send reload signal to all child processes.
             $reloadable_pid_array = [];
             $reloadable_pid_array = [];
@@ -1787,11 +1783,8 @@ class Worker
             static::log("Workerman[" . \basename(static::$_startFile) . "] stopping ...");
             static::log("Workerman[" . \basename(static::$_startFile) . "] stopping ...");
             $worker_pid_array = static::getAllWorkerPids();
             $worker_pid_array = static::getAllWorkerPids();
             // Send stop signal to all child processes.
             // Send stop signal to all child processes.
-            if (static::$_gracefulStop) {
-                $sig = \SIGQUIT;
-            } else {
-                $sig = \SIGINT;
-            }
+            $sig = static::$_gracefulStop ? \SIGQUIT : \SIGINT;
+
             foreach ($worker_pid_array as $worker_pid) {
             foreach ($worker_pid_array as $worker_pid) {
                 \posix_kill($worker_pid, $sig);
                 \posix_kill($worker_pid, $sig);
                 if(!static::$_gracefulStop){
                 if(!static::$_gracefulStop){