Skip to content

Commit

Permalink
suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
reithor authored and adamwojs committed Dec 19, 2024
1 parent f3b1baa commit c6ec806
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,15 @@ private function getPhpPath()
private function getNumberOfCPUCores()
{
$cores = 1;
if (isset($_SERVER['PLATFORM_BRANCH']) && is_file('/run/config.json')) {
if (isset($_SERVER['PLATFORM_BRANCH']) && is_readable('/run/config.json')) {
// Ibexa Cloud: read #cpus from config
$config_json_encoded = file_get_contents('/run/config.json');
if ($config_json_encoded == false) {
$configJsonEncoded = file_get_contents('/run/config.json');
if ($configJsonEncoded === false) {
return 1;
}
$config_json = json_decode($config_json_encoded);
$cores = isset($config_json->info->limits->cpu) ? max(1, floor($config_json->info->limits->cpu)) : 1;

return (int)$cores;
} elseif (is_file('/proc/cpuinfo')) {
$configJson = json_decode($configJsonEncoded);
$cores = isset($configJson->info->limits->cpu) ? max(1, (int) ($configJson->info->limits->cpu)) : 1;
} elseif (is_readable('/proc/cpuinfo')) {
// Linux (and potentially Windows with linux sub systems)
$cpuinfo = file_get_contents('/proc/cpuinfo');
preg_match_all('/^processor/m', $cpuinfo, $matches);
Expand Down

0 comments on commit c6ec806

Please sign in to comment.