通过信号启动workerman状态

U-KNOW

问题描述

我想实现就是在页面获取到 workerman进程的一些信息,也就是 命令行

 php start.php status

的结果展示。

我的代码

页面入口

public function info()
    {
        $data = [];
        //获取进程pid
        $files              = glob(self::$workerManVendorPath."*.pid");
        $data['master_pid'] = $files ? file_get_contents($files[0]) : 0;
        $fp                 = stream_socket_client("tcp://127.0.0.1:9501", $errno, $errstr, 10);

        if (!$fp) {
            echo "$errstr ($errno)<br />\n";
        } else {
            @fwrite($fp, '{"type":"server_monitor"}'."\n");
            while (!feof($fp)) {
                $info .= fread($fp, 1024);
            }
            fclose($fp);
        }
        $info                        = json_decode($info, true);
        $data['process_status_info'] = $info['process_status_info'];
        $data['online_user_info']    = $info['online_user_info'];
        $this->response(0, '', $data);
        exit;
    }

Task_handle 代码

   public static function onMessage($connection, $message)
    {
        $message_data = json_decode($message, true);
        if (!$message_data) {
            return;
        }

        switch ($message_data['type']) {

         //服务状态监控
            case 'server_monitor':
                //发送status信号
                $to_client_info = [];
                posix_kill(posix_getppid(), SIGUSR2);
                $files        = glob(self::$workerManVendorPath."*.status");
                $process_info = $files ? file_get_contents($files[0]) : '';
                //转换为html显示
                $process_info                          = str_replace(array("\n", "\t"), array("<br>", "&nbsp;&nbsp;&nbsp;&nbsp;"), $process_info);
                $to_client_info['process_status_info'] = $process_info;
                Gateway::$registerAddress              = '127.0.0.1:1238';
                $client_info                           = Gateway::getAllClientSessions();
                $to_client_info['online_user_info']    = $client_info;
                //发送给客户端
                $connection->send(json_encode($to_client_info));
                $connection->close();
                return;

        }
  }     

但是 posix_kill(posix_getppid(), SIGUSR2);并没有起到效果,vendor\workerman下也没有生成 status日志文件

721 0 0
0个回答

年代过于久远,无法发表回答
×
🔝