Skip to content

Commit bb16ceb

Browse files
committed
remove pcntl. the consequence is blinking cursor on monitor command, coz cursor hide and show mechanism cannot be restored without pcntl sigterm
1 parent c08817b commit bb16ceb

1 file changed

Lines changed: 10 additions & 33 deletions

File tree

Commands/Monitor.php

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ protected function doExecute(): int
3737
$systemCheck->checkRedisIsInstalled();
3838
}
3939

40-
if (!$this->isPcntlFunctionAvailable()) {
41-
$output->write(str_repeat("\r\n", 100));
42-
$output->write("\e[".(100)."A");
43-
}
40+
$output->write(str_repeat("\r\n", 100));
41+
$output->write("\e[".(100)."A");
4442

4543
$iterations = $this->getIterationsFromArg();
4644
if ($iterations !== null) {
@@ -73,36 +71,26 @@ protected function doExecute(): int
7371
$qCount = count($queues);
7472
$qPerPAge = min(max($this->getPerPageFromArg(), 1), $qCount);
7573
$qPageCount = ceil($qCount / $qPerPAge);
76-
77-
$signalTrap = function() use ($output) {
78-
$output->writeln("\e[u\e[?25h");
79-
die;
80-
};
81-
if ($this->isPcntlFunctionAvailable())
82-
{
83-
pcntl_signal(SIGINT, $signalTrap);
84-
pcntl_signal(SIGTERM, $signalTrap);
85-
}
8674

8775
readline_callback_handler_install('', function() {});
8876
stream_set_blocking (STDIN, false);
8977

9078
$output->writeln(str_repeat("-", 30));
9179
$output->writeln("<fg=black;bg=white;options=bold>".str_pad(" Q INDEX", 10).str_pad(" | REQUEST SETS", 20)."</>");
9280
$output->writeln(str_repeat("-", 30));
93-
$output->write("\e[?25l");
9481

9582
$lastStatsTimer = microtime(true) - 2;
9683
$lastSumInQueue = false;
9784
$diffSumInQueue = 0;
9885
$keyPressed = "";
99-
while (1) {
100-
if ($this->isPcntlFunctionAvailable()) {
101-
pcntl_signal_dispatch();
102-
}
10386

87+
$output->write(str_repeat("\r\n", $qPerPAge + 5));
88+
89+
while (1) {
10490
if (microtime(true) - $lastStatsTimer >= 2 || $keyPressed != "")
10591
{
92+
$output->write("\e[".($qPerPAge + 5)."A");
93+
10694
$qCurrentPage = min(max($qCurrentPage, 1), $qPageCount);
10795
$memory = $backend->getMemoryStats(); // I know this will only work with redis currently as it is not defined in backend interface etc. needs to be refactored once we add another backend
10896

@@ -141,10 +129,7 @@ protected function doExecute(): int
141129
$memory['used_memory_peak_human'] ?? 'Unknown',
142130
$lock->getNumberOfAcquiredLocks()
143131
));
144-
$output->write("\e[s");
145-
$output->write("\e[0G");
146-
$output->write("\e[".($qPerPAge + 5)."A");
147-
132+
148133
if (!is_null($iterations)) {
149134
$iterationCount += 1;
150135
if ($iterationCount >= $iterations) {
@@ -183,7 +168,8 @@ protected function doExecute(): int
183168
$qCurrentPage = $qPageCount;
184169
break;
185170
case "q":
186-
$signalTrap();
171+
$output->writeln('');
172+
die;
187173
}
188174
}
189175

@@ -232,13 +218,4 @@ private function getPerPageFromArg()
232218
}
233219
return $perPage;
234220
}
235-
236-
private function isPcntlFunctionAvailable()
237-
{
238-
if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) {
239-
return true;
240-
}
241-
242-
return false;
243-
}
244221
}

0 commit comments

Comments
 (0)