luya\helpers\FileHelper::humanReadableFilesize PHP Method

humanReadableFilesize() public static method

Generate a human readable size informations from provided Byte/s size
public static humanReadableFilesize ( integer $size ) : string
$size integer The size to convert in Byte
return string The readable size definition
    public static function humanReadableFilesize($size)
    {
        $mod = 1024;
        $units = explode(' ', 'B KB MB GB TB PB');
        for ($i = 0; $size > $mod; ++$i) {
            $size /= $mod;
        }
        return round($size, 2) . ' ' . $units[$i];
    }

Usage Example

 public function actionIndex()
 {
     try {
         // sart time measuremnt
         $start = microtime(true);
         if ($this->verbose) {
             $this->output('[==================== VERBOSE ====================]');
         }
         $container = new CrawlContainer(['baseUrl' => $this->module->baseUrl, 'filterRegex' => $this->module->filterRegex, 'verbose' => $this->verbose, 'doNotFollowExtensions' => $this->module->doNotFollowExtensions, 'useH1' => $this->module->useH1]);
         if ($this->verbose) {
             $this->output('[================== VERBOSE END ==================]');
         }
         $timeElapsed = round((microtime(true) - $start) / 60, 2);
         $this->outputInfo('CRAWLER REPORT:');
         foreach ($container->getReport() as $type => $items) {
             if (count($items) > 0) {
                 $this->outputInfo(PHP_EOL . ' ' . $type . ':');
                 foreach ($items as $message) {
                     $this->output(' - ' . $message);
                 }
             }
         }
         $this->outputInfo(PHP_EOL . 'memory usage: ' . FileHelper::humanReadableFilesize(memory_get_usage()));
         $this->outputInfo('memory peak usage: ' . FileHelper::humanReadableFilesize(memory_get_peak_usage()));
         return $this->outputSuccess(PHP_EOL . 'Crawler finished in ' . $timeElapsed . ' min.');
     } catch (\Exception $e) {
         return $this->outputError('Exception in file "' . $e->getFile() . '" on line #' . $e->getLine() . ': ' . $e->getMessage());
     }
 }
All Usage Examples Of luya\helpers\FileHelper::humanReadableFilesize