Skip to content

Commit

Permalink
Merged branch '4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Dec 20, 2024
2 parents d5df651 + 90f0c81 commit 773c7d0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

class ReindexCommand extends Command
{
private const string IBEXA_CLOUD_CONFIG_FILE = '/run/config.json';
private const string LINUX_CPUINFO_FILE = '/proc/cpuinfo';

protected static $defaultName = 'ibexa:reindex';

protected static $defaultDescription = 'Recreates or refreshes the search engine index';
Expand Down Expand Up @@ -434,9 +437,17 @@ private function getPhpPath()
private function getNumberOfCPUCores(): int
{
$cores = 1;
if (is_file('/proc/cpuinfo')) {
if (isset($_SERVER['PLATFORM_BRANCH']) && is_readable(self::IBEXA_CLOUD_CONFIG_FILE) && is_file(self::IBEXA_CLOUD_CONFIG_FILE)) {
// Ibexa Cloud: read #cpus from config
$configJsonEncoded = file_get_contents(self::IBEXA_CLOUD_CONFIG_FILE);
if ($configJsonEncoded === false) {
return 1;
}
$configJson = json_decode($configJsonEncoded);
$cores = isset($configJson->info->limits->cpu) ? max(1, (int) ($configJson->info->limits->cpu)) : 1;
} elseif (is_readable(self::LINUX_CPUINFO_FILE) && is_file(self::LINUX_CPUINFO_FILE)) {
// Linux (and potentially Windows with linux sub systems)
$cpuinfo = file_get_contents('/proc/cpuinfo');
$cpuinfo = file_get_contents(self::LINUX_CPUINFO_FILE);
preg_match_all('/^processor/m', $cpuinfo, $matches);
$cores = count($matches[0]);
} elseif (DIRECTORY_SEPARATOR === '\\') {
Expand Down

0 comments on commit 773c7d0

Please sign in to comment.