You are here

function apdqc_install_byte2human in Asynchronous Prefetch Database Query Cache 7

Converts a number of bytes into human readable format.

Parameters

string $bytes: Number to convert into a more human readable format.

int $precision: Number of decimals to output.

Return value

string Human readable format of the bytes.

1 call to apdqc_install_byte2human()
apdqc_requirements in ./apdqc.install
Implements hook_requirements().

File

./apdqc.install, line 1807
Handles APDQC installation and status checks.

Code

function apdqc_install_byte2human($bytes, $precision = 0) {
  $units = array(
    '',
    'K',
    'M',
    'G',
    'T',
  );
  $bytes = max($bytes, 0);
  $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  $pow = min($pow, count($units) - 1);
  $bytes /= 1 << 10 * $pow;
  $output = ceil(round($bytes, $precision + 2) * 10) / 10;
  return $output . '' . $units[$pow];
}