Browse Source

Merge pull request #917 from akotulu/master

Fixed typos, removed PHPStorm attributes and change DEBUG to USER
walkor 2 years ago
parent
commit
3e6090d2f2

+ 1 - 1
src/Connection/AsyncTcpConnection.php

@@ -301,7 +301,7 @@ class AsyncTcpConnection extends TcpConnection
             }
             return;
         }
-        // Add socket to global event loop waiting connection is successfully established or faild.
+        // Add socket to global event loop waiting connection is successfully established or failed.
         $this->eventLoop->onWritable($this->socket, [$this, 'checkConnection']);
         // For windows.
         if (DIRECTORY_SEPARATOR === '\\' && method_exists($this->eventLoop, 'onExcept')) {

+ 2 - 4
src/Connection/TcpConnection.php

@@ -15,7 +15,6 @@ declare(strict_types=1);
 
 namespace Workerman\Connection;
 
-use JetBrains\PhpStorm\Pure;
 use JsonSerializable;
 use stdClass;
 use Throwable;
@@ -898,7 +897,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      *
      * return bool.
      */
-    #[Pure]
     public function isIpV4(): bool
     {
         if ($this->transport === 'unix') {
@@ -912,7 +910,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      *
      * return bool.
      */
-    #[Pure]
     public function isIpV6(): bool
     {
         if ($this->transport === 'unix') {
@@ -1038,7 +1035,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      *
      * @param mixed $value
      */
-    public static function enableCache(bool $value = true)
+    public static function enableCache(bool $value = true): void
     {
         static::$enableCache = $value;
     }
@@ -1069,6 +1066,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      * Destruct.
      *
      * @return void
+     * @throws Throwable
      */
     public function __destruct()
     {

+ 0 - 8
src/Connection/UdpConnection.php

@@ -16,8 +16,6 @@ declare(strict_types=1);
 
 namespace Workerman\Connection;
 
-use JetBrains\PhpStorm\ArrayShape;
-use JetBrains\PhpStorm\Pure;
 use JsonSerializable;
 use Workerman\Protocols\ProtocolInterface;
 use function stream_socket_get_name;
@@ -191,7 +189,6 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable
      *
      * return bool.
      */
-    #[Pure]
     public function isIpV4(): bool
     {
         if ($this->transport === 'unix') {
@@ -205,7 +202,6 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable
      *
      * return bool.
      */
-    #[Pure]
     public function isIpV6(): bool
     {
         if ($this->transport === 'unix') {
@@ -229,10 +225,6 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable
      *
      * @return array
      */
-    #[ArrayShape([
-        'transport' => "string", 'getRemoteIp' => "string", 'remotePort' => "int", 'getRemoteAddress' => "string",
-        'getLocalIp' => "string", 'getLocalPort' => "int", 'getLocalAddress' => "string", 'isIpV4' => "bool", 'isIpV6' => "bool"]
-    )]
     public function jsonSerialize(): array
     {
         return [

+ 1 - 1
src/Events/Select.php

@@ -380,7 +380,7 @@ class Select implements EventInterface
             if ($read || $write || $except) {
                 // Waiting read/write/signal/timeout events.
                 try {
-                    @stream_select($read, $write, $except, 0, $this->selectTimeout);
+                    stream_select($read, $write, $except, 0, $this->selectTimeout);
                 } catch (Throwable) {
                 }
             } else {

+ 2 - 2
src/Protocols/Websocket.php

@@ -242,7 +242,7 @@ class Websocket
      * @param mixed $buffer
      * @param TcpConnection $connection
      * @return string
-     * @throws Exception
+     * @throws Throwable
      */
     public static function encode(mixed $buffer, TcpConnection $connection): string
     {
@@ -362,7 +362,7 @@ class Websocket
                 $SecWebSocketKey = $match[1];
             } else {
                 $connection->close(
-					"HTTP/1.0 200 OK\r\nServer: workerman\r\n\r\n<div style=\"text-align:center\"><h1>WebSocket</h1><hr>workerman</div>", true);
+                    "HTTP/1.0 200 OK\r\nServer: workerman\r\n\r\n<div style=\"text-align:center\"><h1>WebSocket</h1><hr>workerman</div>", true);
                 return 0;
             }
             // Calculation websocket key.

+ 19 - 13
src/Worker.php

@@ -620,7 +620,7 @@ class Worker
                 @mkdir(dirname(static::$logFile), 0777, true);
             }
             touch(static::$logFile);
-            chmod(static::$logFile, 0622);
+            chmod(static::$logFile, 0644);
         }
 
         // State.
@@ -761,7 +761,7 @@ class Worker
     }
 
     /**
-     * Get unix user of current porcess.
+     * Get unix user of current process.
      *
      * @return string
      */
@@ -792,7 +792,7 @@ class Worker
 
         //show version
         $lineVersion = 'Workerman version:' . static::VERSION . str_pad('PHP version:', 16, ' ', STR_PAD_LEFT) . PHP_VERSION . str_pad('Event-loop:', 16, ' ', STR_PAD_LEFT) . static::getEventLoopName() . PHP_EOL;
-        !defined('LINE_VERSIOIN_LENGTH') && define('LINE_VERSIOIN_LENGTH', strlen($lineVersion));
+        !defined('LINE_VERSION_LENGTH') && define('LINE_VERSION_LENGTH', strlen($lineVersion));
         $totalLength = static::getSingleLineTotalLength();
         $lineOne = '<n>' . str_pad('<w> WORKERMAN </w>', $totalLength + strlen('<w></w>'), '-', STR_PAD_BOTH) . '</n>' . PHP_EOL;
         $lineTwo = str_pad('<w> WORKERS </w>', $totalLength + strlen('<w></w>'), '-', STR_PAD_BOTH) . PHP_EOL;
@@ -827,6 +827,8 @@ class Worker
 
         if (static::$daemonize) {
             static::safeEcho('Input "php ' . basename(static::$startFile) . ' stop" to stop. Start success.' . "\n\n");
+        } else if (!empty(static::$command)) {
+            static::safeEcho("Start success.\n"); // Workerman used as library
         } else {
             static::safeEcho("Press Ctrl+C to stop. Start success.\n");
         }
@@ -867,8 +869,8 @@ class Worker
         }
 
         //Keep beauty when show less columns
-        !defined('LINE_VERSIOIN_LENGTH') && define('LINE_VERSIOIN_LENGTH', 0);
-        $totalLength <= LINE_VERSIOIN_LENGTH && $totalLength = LINE_VERSIOIN_LENGTH;
+        !defined('LINE_VERSION_LENGTH') && define('LINE_VERSION_LENGTH', 0);
+        $totalLength <= LINE_VERSION_LENGTH && $totalLength = LINE_VERSION_LENGTH;
 
         return $totalLength;
     }
@@ -886,7 +888,7 @@ class Worker
 
         // Check argv;
         $startFile = basename(static::$startFile);
-        $usage = "Usage: php yourfile <command> [mode]\nCommands: \nstart\t\tStart worker in DEBUG mode.\n\t\tUse mode -d to start in DAEMON mode.\nstop\t\tStop worker.\n\t\tUse mode -g to stop gracefully.\nrestart\t\tRestart workers.\n\t\tUse mode -d to start in DAEMON mode.\n\t\tUse mode -g to stop gracefully.\nreload\t\tReload codes.\n\t\tUse mode -g to reload gracefully.\nstatus\t\tGet worker status.\n\t\tUse mode -d to show live status.\nconnections\tGet worker connections.\n";
+        $usage = "Usage: php yourfile <command> [mode]\nCommands: \nstart\t\tStart worker in USER mode.\n\t\tUse mode -d to start in DAEMON mode.\nstop\t\tStop worker.\n\t\tUse mode -g to stop gracefully.\nrestart\t\tRestart workers.\n\t\tUse mode -d to start in DAEMON mode.\n\t\tUse mode -g to stop gracefully.\nreload\t\tReload codes.\n\t\tUse mode -g to reload gracefully.\nstatus\t\tGet worker status.\n\t\tUse mode -d to show live status.\nconnections\tGet worker connections.\n";
         $availableCommands = [
             'start',
             'stop',
@@ -919,7 +921,7 @@ class Worker
             if ($mode === '-d' || static::$daemonize) {
                 $modeStr = 'in DAEMON mode';
             } else {
-                $modeStr = 'in DEBUG mode';
+                $modeStr = 'in USER mode';
             }
         }
         static::log("Workerman[$startFile] $command $modeStr");
@@ -973,9 +975,9 @@ class Worker
                 }
                 // Master process will send SIGIO signal to all child processes.
                 posix_kill($masterPid, SIGIO);
-                // Waiting amoment.
+                // Waiting a moment.
                 usleep(500000);
-                // Display statisitcs data from a disk file.
+                // Display statistics data from a disk file.
                 if (is_readable($statisticsFile)) {
                     readfile($statisticsFile);
                 }
@@ -1005,7 +1007,7 @@ class Worker
                             static::log("Workerman[$startFile] stop fail");
                             exit;
                         }
-                        // Waiting amoment.
+                        // Waiting a moment.
                         usleep(10000);
                         continue;
                     }
@@ -1169,7 +1171,7 @@ class Worker
      * Signal handler.
      *
      * @param int $signal
-     * @throws Exception
+     * @throws Throwable
      */
     public static function signalHandler(int $signal): void
     {
@@ -1788,7 +1790,7 @@ class Worker
      * Execute reload.
      *
      * @return void
-     * @throws Exception
+     * @throws Throwable
      */
     protected static function reload(): void
     {
@@ -1871,6 +1873,7 @@ class Worker
      *
      * @param int $code
      * @param mixed $log
+     * @throws Throwable
      */
     public static function stopAll(int $code = 0, mixed $log = ''): void
     {
@@ -2452,6 +2455,7 @@ class Worker
      * Stop current worker instance.
      *
      * @return void
+     * @throws Throwable
      */
     public function stop(): void
     {
@@ -2466,7 +2470,7 @@ class Worker
         // Remove listener for server socket.
         $this->unlisten();
         // Close all connections for the worker.
-        if (!static::$gracefulStop) {
+        if (static::$gracefulStop) {
             foreach ($this->connections as $connection) {
                 $connection->close();
             }
@@ -2486,6 +2490,7 @@ class Worker
      *
      * @param resource $socket
      * @return void
+     * @throws Throwable
      */
     public function acceptTcpConnection($socket): void
     {
@@ -2527,6 +2532,7 @@ class Worker
      *
      * @param resource $socket
      * @return bool
+     * @throws Throwable
      */
     public function acceptUdpConnection($socket): bool
     {