Symfony\Component\Console\Helper\Helper::formatMemory PHP Method

formatMemory() public static method

public static formatMemory ( $memory )
    public static function formatMemory($memory)
    {
        if ($memory >= 1024 * 1024 * 1024) {
            return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
        }
        if ($memory >= 1024 * 1024) {
            return sprintf('%.1f MiB', $memory / 1024 / 1024);
        }
        if ($memory >= 1024) {
            return sprintf('%d KiB', $memory / 1024);
        }
        return sprintf('%d B', $memory);
    }

Usage Example

示例#1
0
 protected function getProgressBar($nbIteration, $message)
 {
     $bar = new ProgressBar($this->output, $nbIteration);
     ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) {
         static $i = 0;
         $mem = memory_get_usage();
         $colors = $i++ ? '41;37' : '44;37';
         return "[" . $colors . 'm ' . Helper::formatMemory($mem) . " ";
     });
     $bar->setFormat("  %title:-38s% \n %current%/%max% %bar% %percent:3s%%\n 🏁  %remaining:-10s% %memory:37s%\n");
     $bar->setBarCharacter("●");
     $bar->setEmptyBarCharacter("●");
     $bar->setMessage($message, 'title');
     $bar->start();
     return $bar;
 }
All Usage Examples Of Symfony\Component\Console\Helper\Helper::formatMemory