src/Command/ServerCommand.php
public function stop()
    {
        if (!$this->isRunning()) {
            smproxy_error('ERROR: The server is not running! cannot stop!');
        }

        echo 'SMProxy is stopping ...', PHP_EOL;

        $result = function () {
            // 获取master进程ID
            $masterPid = $this->serverSetting['masterPid'];
            // 使用swoole_process::kill代替posix_kill
            \swoole_process::kill($masterPid);
            $timeout = 60;
            $startTime = time();
            while (true) {
                // Check the process status
                if (\swoole_process::kill($masterPid, 0)) {
                    // 判断是否超时
                    if (time() - $startTime >= $timeout) {
                        return false;
                    }
                    usleep(10000);
                    continue;
                }

                return true;
            }
        };

        // 停止失败
        if (!$result()) {
            smproxy_error('SMProxy shutting down failed!');
        }

        // 删除pid文件
        @unlink(CONFIG['server']['swoole']['pid_file']);

        echo 'SMProxy has been shutting down.', PHP_EOL;
    }
public function stop()
    {
        if (!$this->isRunning()) {
            smproxy_error('ERROR: The server is not running! cannot stop!');
        }

        echo 'SMProxy is stopping ...', PHP_EOL;

        $result = function () {
            // 获取master进程ID
            $masterPid = $this->serverSetting['masterPid'];
            // 使用swoole_process::kill代替posix_kill
            \swoole_process::kill($masterPid);
            $timeout = 60;
            $startTime = time();
            while (true) {
                // Check the process status
                if (\swoole_process::kill($masterPid, 0)) {
                    // 判断是否超时
                    if (time() - $startTime >= $timeout) {
                        return false;
                    }
                    usleep(10000);
                    continue;
                }

                return true;
            }
        };

        // 停止失败
        if (!$result()) {
            smproxy_error('SMProxy shutting down failed!');
        }

        // 删除pid文件
        @unlink(CONFIG['server']['swoole']['pid_file']);

        echo 'SMProxy has been shutting down.', PHP_EOL;
    }
停止服务.