Procházet zdrojové kódy

Check __destruct isSafe

walkor před 11 měsíci
rodič
revize
517ef664db
1 změnil soubory, kde provedl 20 přidání a 0 odebrání
  1. 20 0
      src/Connection/TcpConnection.php

+ 20 - 0
src/Connection/TcpConnection.php

@@ -245,6 +245,13 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     public ?Request $request = null;
 
     /**
+     * Is safe.
+     *
+     * @var bool
+     */
+    protected bool $isSafe = true;
+
+    /**
      * Default send buffer size.
      *
      * @var int
@@ -1103,6 +1110,16 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     }
 
     /**
+     * __wakeup.
+     *
+     * @return void
+     */
+    public function __wakeup()
+    {
+        $this->isSafe = false;
+    }
+
+    /**
      * Destruct.
      *
      * @return void
@@ -1110,6 +1127,9 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     public function __destruct()
     {
         static $mod;
+        if (!$this->isSafe) {
+            return;
+        }
         self::$statistics['connection_count']--;
         if (Worker::getGracefulStop()) {
             $mod ??= ceil((self::$statistics['connection_count'] + 1) / 3);