walkor преди 2 години
родител
ревизия
002689ae2f
променени са 2 файла, в които са добавени 12 реда и са изтрити 5 реда
  1. 1 1
      src/Timer.php
  2. 11 4
      src/Worker.php

+ 1 - 1
src/Timer.php

@@ -167,7 +167,7 @@ class Timer
                 return null;
         }
         // Swow or non coroutine environment
-        msleep($delay * 1000);
+        usleep($delay * 1000 * 1000);
         return null;
     }
 

+ 11 - 4
src/Worker.php

@@ -1620,6 +1620,10 @@ class Worker
                 foreach (static::$pidMap as $workerId => $workerPidArray) {
                     if (isset($workerPidArray[$pid])) {
                         $worker = static::$workers[$workerId];
+                        // Fix exit with status 2 for php8.2
+                        if ($status === \SIGINT && static::$status === static::STATUS_SHUTDOWN) {
+                            $status = 0;
+                        }
                         // Exit status.
                         if ($status !== 0) {
                             static::log("worker[{$worker->name}:$pid] exit with status $status");
@@ -1806,12 +1810,15 @@ class Worker
             $workerPidArray = static::getAllWorkerPids();
             // Send stop signal to all child processes.
             $sig = static::$gracefulStop ? \SIGQUIT : \SIGINT;
-            // Fix exit with status 2
-            usleep(50000);
             foreach ($workerPidArray as $workerPid) {
-                \posix_kill($workerPid, $sig);
+                // Fix exit with status 2 for php8.2
+                if ($sig === \SIGINT && !Worker::$daemonize) {
+                    Timer::add(1, '\posix_kill', [$workerPid, \SIGINT], false);
+                } else {
+                    \posix_kill($workerPid, $sig);
+                }
                 if(!static::$gracefulStop){
-                    Timer::add(static::$stopTimeout, '\posix_kill', [$workerPid, \SIGKILL], false);
+                    Timer::add(ceil(static::$stopTimeout), '\posix_kill', [$workerPid, \SIGKILL], false);
                 }
             }
             Timer::add(1, "\\Workerman\\Worker::checkIfChildRunning");