• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IlyasDeckers / ody-core / 13575371463

27 Feb 2025 08:34PM UTC coverage: 28.921% (+0.6%) from 28.348%
13575371463

push

github

IlyasDeckers
Refactoring/cleaning up/getting rid of redundant helper functions

0 of 68 new or added lines in 8 files covered. (0.0%)

9 existing lines in 5 files now uncovered.

544 of 1881 relevant lines covered (28.92%)

8.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Console/Commands/StatusCommand.php
1
<?php
2

3
namespace Ody\Core\Console\Commands;
4

5
use Ody\Swoole\ServerState;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12

13
#[AsCommand(
14
    name: 'server:status',
×
15
    description: 'server status'
×
16
)]
×
17
class StatusCommand extends Command
18
{
19
    protected function configure(): void
×
20
    {
21
        $this->addOption('full', 'f', InputOption::VALUE_NONE, 'Display full information about the status of processes');
×
22
    }
23

24
    protected function execute(InputInterface $input, OutputInterface $output): int
×
25
    {
26
        if ($input->getOption('full')) {
×
27
            $this->fullInformation($output);
×
28
        } else {
29
            $this->generalInformation($output);
×
30
        }
31

32
        return self::SUCCESS;
×
33
    }
34

35
    protected function fullInformation(OutputInterface $output): void
×
36
    {
NEW
37
        $serverState = ServerState::getInstance();
×
NEW
38
        $rows = $this->getGeneralInformationTable($serverState);
×
39

NEW
40
        foreach ($serverState->getWorkerProcessIds() as $index => $workerId) {
×
41
            $index++;
×
42
            if (posix_kill($workerId, SIG_DFL)) {
×
43
                $rows[] = [
×
44
                    "HTTP process $index",
×
45
                    '<fg=#C3E88D;options=bold> ACTIVE </>',
×
46
                    $workerId
×
47
                ];
×
48
                continue;
×
49
            }
50
            $rows[] = [
×
51
                "Worker worker $index",
×
52
                '<fg=#FF5572;options=bold> DEACTIVE </>',
×
53
                $workerId
×
54
            ];
×
55
        }
56

NEW
57
        foreach ($serverState->getWebsocketWorkerProcessIds() as $index => $workerId) {
×
58
            $index++;
×
59
            if (posix_kill($workerId, SIG_DFL)) {
×
60
                $rows[] = [
×
61
                    "Websocket process $index",
×
62
                    '<fg=#C3E88D;options=bold> ACTIVE </>',
×
63
                    $workerId
×
64
                ];
×
65
                continue;
×
66
            }
67
            $rows[] = [
×
68
                "Worker worker $index",
×
69
                '<fg=#FF5572;options=bold> DEACTIVE </>',
×
70
                $workerId
×
71
            ];
×
72
        }
73

74
        $output->writeln('');
×
75
        $table = new Table($output);
×
76
        $table
×
77
            ->setHeaderTitle('full information')
×
78
            ->setHeaders([
×
79
                '<fg=#FFCB8B;options=bold> Process Name </>',
×
80
                '<fg=#FFCB8B;options=bold> Process Status </>',
×
81
                '<fg=#FFCB8B;options=bold> Process PID </>'
×
82
            ])
×
83
            ->setRows($rows);
×
84
        $table->setVertical();
×
85
        $table->render();
×
86
        $output->writeln('');
×
87
    }
88

89
    protected function generalInformation(OutputInterface $output): void
×
90
    {
91
        $output->writeln('');
×
92
        $table = new Table($output);
×
93
        $table
×
94
            ->setHeaderTitle('general information')
×
95
            ->setHeaders([
×
96
                '<fg=#FFCB8B;options=bold> Process Name </>',
×
97
                '<fg=#FFCB8B;options=bold> Process Status </>',
×
98
                '<fg=#FFCB8B;options=bold> Process PID </>'
×
99
            ])
×
NEW
100
            ->setRows($this->getGeneralInformationTable(ServerState::getInstance()));
×
101
        $table->setVertical();
×
102
        $table->render();
×
103
        $output->writeln('');
×
104
    }
105

106
    /**
107
     * @param ServerState $serverState
108
     * @return array
109
     */
NEW
110
    private function getGeneralInformationTable(ServerState $serverState): array
×
111
    {
NEW
112
        $processIds = [
×
NEW
113
            'manager' => $serverState->getManagerProcessId(),
×
NEW
114
            'master' => $serverState->getMasterProcessId(),
×
NEW
115
            'watcher' => $serverState->getWatcherProcessId(),
×
NEW
116
//            'factory' => $serverState->getFactoryProcessId(),
×
NEW
117
//            'queue' => $serverState->getQueueProcessId(),
×
NEW
118
        ];
×
119

NEW
120
        $rows = [];
×
NEW
121
        $i = 0;
×
NEW
122
        foreach ($processIds as $key => $processId) {
×
NEW
123
            $rows[$i] = [
×
NEW
124
                $key,
×
NEW
125
                !is_null($processId) && posix_kill($processId, SIG_DFL) ? '<fg=#C3E88D;options=bold> ACTIVE </>' : '<fg=#FF5572;options=bold> DEACTIVE </>', $processId
×
NEW
126
            ];
×
NEW
127
            $i++;
×
128
        }
129

NEW
130
        return $rows;
×
131
    }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc