The daemon stop command.
@return int
321829
public function actionStop()
    {
        $message = 'Stopping Yii 2 Daemon ' . $this->version . '... ';
        $result = static::EXIT_CODE_NORMAL;
        if ($this->_getPid() !== false) {
            $this->_killPid();
            $message .= 'OK.';
        } else {
            $message .= 'Service is not running!';
            $result = static::EXIT_CODE_ERROR;
        }
        echo $message . PHP_EOL;
        $this->_log($message);
        return $result;
    }
243339
def stop(self):
        
        self.child.terminate()
        self._cleanup()
        return self.child.exitcode
512468
public function throttle()
    {
        if ((time() - $this->lastCpuCheck) >= $this->cpuCheckFrequency) {
            $load = sys_getloadavg();
            
            if ($load[0]/$this->cpuCount >= $this->cpuTarget) {
                $this->pause += $this->throttleSensitivity;
                $this->controller->notify('Daemon throttling down');
            } else {
                $this->pause -= $this->throttleSensitivity;
                $this->controller->notify('Daemon throttling up');
            }

            $this->lastCpuCheck = time();
        }

        // Never allow pause to dip below 1 microsecond
        if ($this->pause < 1) {
            $this->pause = 1;
        }

        return $this->pause;
    }
807011
function stop() {
        if($this->timer) {
            self::$loop->cancelTimer($this->timer);
            $this->timer = null;
        }
        
        $this->emitter->removeListener($this->event, $this->listener);
        
        $errors = (array) ($this->options['errors'] ?? array());
        if(\in_array('max', $errors, true) && ($this->options['max'] ?? 0) > 0 && $this->bucket->count() < $this->options['max']) {
            $reject = $this->reject;
            $reject(new \RangeException('Collecting timed out (max not reached in time)'));
            return;
        }
        
        $resolve = $this->resolve;
        $resolve($this->bucket);
    }
480170
public function stop()
    {

        // load the queue keys
        $queues = get_object_vars($this->getQueues());

        // iterate over the queues and shut them down
        /** @var AppserverIo\Psr\Pms\QueueInterface $queue */
        foreach ($queues as $queue) {
            $queue->stop();
        }
    }
579137
public static function stopAll()
    {
        static::$_status = static::STATUS_SHUTDOWN;
        // For master process.
        if (static::$_masterPid === posix_getpid()) {
            static::log("Workerman[" . basename(static::$_startFile) . "] stopping ...");
            $worker_pid_array = static::getAllWorkerPids();
            // Send stop signal to all child processes.
            if (static::$_gracefulStop) {
                $sig = SIGTERM;
            } else {
                $sig = SIGINT;
            }
            foreach ($worker_pid_array as $worker_pid) {
                posix_kill($worker_pid, $sig);
                if(!static::$_gracefulStop){
                    Timer::add(static::KILL_WORKER_TIMER_TIME, 'posix_kill', array($worker_pid, SIGKILL), false);
                }
            }
            Timer::add(1, "\\Workerman\\Worker::checkIfChildRunning");
            // Remove statistics file.
            if (is_file(static::$_statisticsFile)) {
                @unlink(static::$_statisticsFile);
            }
        } // For child processes.
        else {
            // Execute exit.
            foreach (static::$_workers as $worker) {
                if(!$worker->stopping){
                    $worker->stop();
                    $worker->stopping = true;
                }
            }
            if (!static::$_gracefulStop || ConnectionInterface::$statistics['connection_count'] <= 0) {
                static::$_workers = array();
                if (static::$globalEvent) {
                    static::$globalEvent->destroy();
                }
                exit(0);
            }
        }
    }
387159
public function stop($async = false)
    {
        $state = $this->getState();

        if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])
            && !$this->processExists()
        ) {
            $this->getLogger()
                ->warning("Daemon is ill cant find process {$this->getProcessId()}, try clean data", [__NAMESPACE__]);

            $this->cleanData();

            return true;
        }


        if (in_array($state, [self::STATE_T_STOP, self::STATE_T_KILL])) {
            $this->getLogger()->info("Daemon can't STOP, cause state : {$state}", [__NAMESPACE__]);

            return true;
        }

        if (!in_array($state, [self::STATE_T_START])) {
            $this->getLogger()->info("Daemon can't STOP, cause daemon not START", [__NAMESPACE__]);

            return true;
        }

        $this->setState(self::STATE_T_STOP);

        // sync mode (wait for stopping loop)

        if ($async) {
            return true;
        }

        $this->getLogger()->info("Daemon sync STOP, wait loop ...", [__NAMESPACE__]);

        $sleep = $this->getConfig(self::CONFIG_SLEEP_STOP_LOOP);
        while ($this->isState(
            [self::STATE_T_STOP, self::STATE_T_KILL, self::STATE_T_START]
        )) {
            $this->getLogger()->debug("Daemon sync STOP, wait loop .......", [__NAMESPACE__]);
            sleep($sleep);
        }

        return true;
    }
628223
public function stop()
    {
        $time = microtime(true);
        $this->time += $time - $this->start;
        $this->start = $time;
        return $this;
    }
177306
public function stop()
    {

        // start container shutdown
        $this->synchronized(function ($self) {
            $self->containerState = ContainerStateKeys::get(ContainerStateKeys::HALT);
        }, $this);

        do {
            // wait for 0.5 seconds
            usleep(500000);

            // log a message that we'll wait till application has been shutdown
            $this->getInitialContext()->getSystemLogger()->info(
                sprintf('Wait for container %s to be shutdown', $this->getContainerNode()->getName())
            );

            // query whether application state key is SHUTDOWN or not
            $waitForShutdown = $this->synchronized(function ($self) {
                return $self->containerState->notEquals(ContainerStateKeys::get(ContainerStateKeys::SHUTDOWN));
            }, $this);

        } while ($waitForShutdown);
    }
727062
public function stop()
    {
        if (!$this->startTime) {
            return false;
        }

        // calc responseTime
        $this->responseTime = $this->getmicrotime() - $this->startTime;
        $this->startTime = 0.0;
    }
703583
public function stop()
    {
        $deferred = new Deferred();

        if ($this->stopAudio) {
            $deferred->reject(new \Exception('Audio is already being stopped.'));

            return $deferred->promise();
        }

        if (! $this->speaking) {
            $deferred->reject(new \Exception('Audio must be playing to stop it.'));

            return $deferred->promise();
        }

        $this->stopAudio = true;

        $deferred->resolve();

        return $deferred->promise();
    }
898846
public function stopAfter(int $seconds): self
    {
        $seconds = 0 >= $seconds ? 1 : $seconds;

        /** @psalm-suppress MixedTypeCoercion Incorrect amphp types */
        Loop::delay(
            $seconds * 1000,
            function() use ($seconds): void
            {
                /** @var LoggerInterface $logger */
                $logger = $this->getKernelContainerService('service_bus.logger');

                $logger->info('The demon\'s lifetime has expired ({lifetime} seconds)', ['lifetime' => $seconds]);

                $this->entryPoint->stop();
            }
        );

        return $this;
    }
1270820
static public function stop()
    {
        if ( !self::$hasStarted )
        {
             return false;
        }
        session_write_close();
        self::$hasStarted = false;
        self::$handlerInstance = null;
        return true;
    }
856028
protected static function daemonize()
    {
        Base::getLog()->debug(__METHOD__ . ' calling daemonize', [
            'daemonize' => self::$daemonize,
        ]);
        if ( ! self::$daemonize)
        {
            return;
        }

        umask(0);
        $pid = pcntl_fork();
        if (-1 === $pid)
        {
            throw new Exception('fork fail');
        }
        elseif ($pid > 0)
        {
            exit(0);
        }
        if (-1 === posix_setsid())
        {
            throw new Exception("setsid fail");
        }
        // fork again avoid SVR4 system regain the control of terminal
        $pid = pcntl_fork();
        if (-1 === $pid)
        {
            throw new Exception("fork fail");
        }
        elseif (0 !== $pid)
        {
            exit(0);
        }
    }
643347
public function stop()
    {
        $data = phpdbg_end_oplog();
        $result = [];
        foreach ($data as $file => $coverage) {
            foreach ($coverage as $line => $value) {
                $result[$file][$line - 1] = $value <= 0 ? 0 : 1;
            }
        }
        return $result;
    }
178522
protected function stopWorkers($n = 1)
    {
        Daemon::log('--' . $n . '-- ' . Debug::backtrace() . '-----');

        $n = (int)$n;
        $i = 0;

        foreach ($this->workers->threads as &$w) {
            if ($i >= $n) {
                break;
            }

            if ($w->shutdown) {
                continue;
            }

            if ($w->reloaded) {
                continue;
            }

            $w->stop();
            ++$i;
        }

        $this->lastMpmActionTs = microtime(true);
        return true;
    }
1085598
function stop(): int {
        if($this->timer === null) {
            return 0;
        }
        
        if($this->nativeHrtime) {
            $elapsed = (int) (\hrtime(true) - $this->timer);
        } elseif($this->hrtime) {
            $this->timer->stop();
            $elapsed = (int) $this->timer->getElapsedTime(\HRTime\Unit::NANOSECOND);
        } else {
            $elapsed = \microtime(true) - $this->timer;
            $elapsed = \ceil(($elapsed * 1000000000));
        }
        
        return ((int) $elapsed);
    }