Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ function (ServerRequestInterface $request) use ($kernelAdapter, $filesystem) {
await($kernelAdapter->shutdown(), $loop);
};

if ($this->serverContext->getGcCollectsInSeconds() > 0) {
$this->loop->addPeriodicTimer($this->serverContext->getGcCollectsInSeconds(), function () {
gc_collect_cycles();
});
}

$this->loop->addSignal(SIGTERM, $signalHandler);
$this->loop->addSignal(SIGINT, $signalHandler);
}
Expand Down
1 change: 1 addition & 0 deletions src/Console/ServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected function configure()
->addOption('request-body-buffer', null, InputOption::VALUE_OPTIONAL, 'Limit of the buffer used for the Request body. In KiB.', 1024)
->addOption('adapter', null, InputOption::VALUE_OPTIONAL, 'Server Adapter. Can be a namespace or a shortcut. Available shortcuts [drift, symfony]', 'drift')
->addOption('allowed-loop-stops', null, InputOption::VALUE_OPTIONAL, 'Number of allowed loop stops', 0)
->addOption('gc-collect-cycles', null, InputOption::VALUE_OPTIONAL, 'Seconds between each force GC collect execution. 0 for disabled.', 0)
->addOption('workers', null, InputOption::VALUE_OPTIONAL,
'Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command.', 1
)
Expand Down
11 changes: 11 additions & 0 deletions src/Context/ServerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ final class ServerContext
private int $workers;
private bool $closeConnections;

private int $gcCollectsInSeconds;

/**
* @param InputInterface $input
*
Expand Down Expand Up @@ -114,6 +116,7 @@ public static function buildByInput(InputInterface $input): ServerContext
$serverContext->limitConcurrentRequests = intval($input->getOption('concurrent-requests'));
$serverContext->requestBodyBuffer = intval($input->getOption('request-body-buffer'));

$serverContext->gcCollectsInSeconds = intval($input->getOption('gc-collect-cycles'));
$serverContext->closeConnections = boolval($input->getOption('close-connections'));
$serverContext->allowedLoopStops = intval($input->getOption('allowed-loop-stops'));
$serverContext->workers = \intval($input->getOption('workers'));
Expand Down Expand Up @@ -320,6 +323,14 @@ public function mustCloseConnections(): bool
return $this->closeConnections;
}

/**
* @return int
*/
public function getGcCollectsInSeconds(): int
{
return $this->gcCollectsInSeconds;
}

/**
* Build queue architecture from array of strings.
*
Expand Down