Skip to content

Commit

Permalink
remove pcntl. the consequence is blinking cursor on monitor command…
Browse files Browse the repository at this point in the history
…, coz cursor hide and show mechanism cannot be restored without pcntl sigterm
  • Loading branch information
haristku committed Oct 16, 2024
1 parent c08817b commit bb16ceb
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions Commands/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ protected function doExecute(): int
$systemCheck->checkRedisIsInstalled();
}

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

$iterations = $this->getIterationsFromArg();
if ($iterations !== null) {
Expand Down Expand Up @@ -73,36 +71,26 @@ protected function doExecute(): int
$qCount = count($queues);
$qPerPAge = min(max($this->getPerPageFromArg(), 1), $qCount);
$qPageCount = ceil($qCount / $qPerPAge);

$signalTrap = function() use ($output) {
$output->writeln("\e[u\e[?25h");
die;
};
if ($this->isPcntlFunctionAvailable())
{
pcntl_signal(SIGINT, $signalTrap);
pcntl_signal(SIGTERM, $signalTrap);
}

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

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

$lastStatsTimer = microtime(true) - 2;
$lastSumInQueue = false;
$diffSumInQueue = 0;
$keyPressed = "";
while (1) {
if ($this->isPcntlFunctionAvailable()) {
pcntl_signal_dispatch();
}

$output->write(str_repeat("\r\n", $qPerPAge + 5));

while (1) {
if (microtime(true) - $lastStatsTimer >= 2 || $keyPressed != "")
{
$output->write("\e[".($qPerPAge + 5)."A");

$qCurrentPage = min(max($qCurrentPage, 1), $qPageCount);
$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

Expand Down Expand Up @@ -141,10 +129,7 @@ protected function doExecute(): int
$memory['used_memory_peak_human'] ?? 'Unknown',
$lock->getNumberOfAcquiredLocks()
));
$output->write("\e[s");
$output->write("\e[0G");
$output->write("\e[".($qPerPAge + 5)."A");


if (!is_null($iterations)) {
$iterationCount += 1;
if ($iterationCount >= $iterations) {
Expand Down Expand Up @@ -183,7 +168,8 @@ protected function doExecute(): int
$qCurrentPage = $qPageCount;
break;
case "q":
$signalTrap();
$output->writeln('');
die;
}
}

Expand Down Expand Up @@ -232,13 +218,4 @@ private function getPerPageFromArg()
}
return $perPage;
}

private function isPcntlFunctionAvailable()
{
if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) {
return true;
}

return false;
}
}

0 comments on commit bb16ceb

Please sign in to comment.