36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
|
|
function cpu_count(): int
|
|
{
|
|
// Windows does not support the number of processes setting.
|
|
if (DIRECTORY_SEPARATOR === '\\') {
|
|
return 1;
|
|
}
|
|
$count = 4;
|
|
if (is_callable('shell_exec')) {
|
|
if (strtolower(PHP_OS) === 'darwin') {
|
|
$count = (int)shell_exec('sysctl -n machdep.cpu.core_count');
|
|
} else {
|
|
try {
|
|
$count = (int)shell_exec('nproc');
|
|
} catch (\Throwable $ex) {
|
|
// Do nothing
|
|
}
|
|
}
|
|
}
|
|
return $count > 0 ? $count : 4;
|
|
}
|
|
function formatSeconds($seconds) {
|
|
$days = floor($seconds / 86400);
|
|
$hours = floor(($seconds % 86400) / 3600);
|
|
$minutes = floor(($seconds % 3600) / 60);
|
|
$secs = $seconds % 60;
|
|
|
|
$result = '';
|
|
if ($days > 0) $result .= $days."D ";
|
|
if ($hours > 0) $result .= $hours."H ";
|
|
if ($minutes > 0) $result .= $minutes."M ";
|
|
if ($secs > 0 || $result === '') $result .= $secs."S";
|
|
|
|
return $result;
|
|
} |