Resque\Helpers\Util::bytes PHP Méthode

bytes() public static méthode

Returns human readable sizes. Based on original functions written by Aidan Lister and Quentin Zervaas.
public static bytes ( integer $bytes, string $force_unit = null, string $format = null, boolean $si = true ) : string
$bytes integer size in bytes
$force_unit string a definitive unit
$format string the return string format
$si boolean whether to use SI prefixes or IEC
Résultat string
    public static function bytes($bytes, $force_unit = null, $format = null, $si = true)
    {
        $format = $format === null ? '%01.2f %s' : (string) $format;
        // IEC prefixes (binary)
        if ($si == false or strpos($force_unit, 'i') !== false) {
            $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
            $mod = 1024;
            // SI prefixes (decimal)
        } else {
            $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB');
            $mod = 1000;
        }
        if (($power = array_search((string) $force_unit, $units)) === false) {
            $power = $bytes > 0 ? floor(log($bytes, $mod)) : 0;
        }
        return sprintf($format, $bytes / pow($mod, $power), $units[$power]);
    }

Usage Example

Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $workers = Resque\Worker::hostWorkers();
     if (empty($workers)) {
         $this->log('<warn>There are no workers on this host.</warn>');
         return;
     }
     $table = new Resque\Helpers\Table($this);
     $table->setHeaders(array('#', 'Status', 'ID', 'Running for', 'Running job', 'P', 'C', 'F', 'Interval', 'Timeout', 'Memory (Limit)'));
     foreach ($workers as $i => $worker) {
         $packet = $worker->getPacket();
         $table->addRow(array($i + 1, Resque\Worker::$statusText[$packet['status']], (string) $worker, Resque\Helpers\Util::human_time_diff($packet['started']), !empty($packet['job_id']) ? $packet['job_id'] . ' for ' . Resque\Helpers\Util::human_time_diff($packet['job_started']) : '-', $packet['processed'], $packet['cancelled'], $packet['failed'], $packet['interval'], $packet['timeout'], Resque\Helpers\Util::bytes($packet['memory']) . ' (' . $packet['memory_limit'] . ' MB)'));
     }
     $this->log((string) $table);
 }
All Usage Examples Of Resque\Helpers\Util::bytes