memory_get_usage

Supported Versions: PHP 4 >= 4.3.2, PHP 5, PHP 7, PHP 8
Returns the amount of memory allocated to PHP
<?php memory_get_usage(bool $real_usage = false): int
<?php     public function memoryExceeded($memoryLimit)

    {

        return (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit;

    }
<?php     public function memoryExceeded($memoryLimit)

    {

        return (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit;

    }
<?php         if ($this->enabled) {

            $this->output->writeln(sprintf(

                '  <fg=gray>Memory:</>   <fg=default>%s MB</>',

                round(memory_get_usage(true) / 1000 ** 2, 3)

            ));

        }
<?php     {

        $garbage = (int) $event->app->make('config')->get('octane.garbage');



        if ($garbage && (memory_get_usage() / 1024 / 1024) > $garbage) {

            gc_collect_cycles();

        }

    }
<?php             'type' => 'request',

            'method' => $method,

            'url' => $url,

            'memory' => memory_get_usage(),

            'statusCode' => $statusCode,

            'duration' => $duration,

        ])."\n");
<?php             }



            if (isset($startTime)) {

                $io->writeError('<info>Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MiB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MiB), time: '.round(microtime(true) - $startTime, 2).'s');

            }



            return $result;
<?php         }



        if (null !== $this->startTime) {

            $memoryUsage = memory_get_usage() / 1024 / 1024;

            $timeSpent = microtime(true) - $this->startTime;

            $messages = array_map(function ($message) use ($memoryUsage, $timeSpent) {

                return sprintf('[%.1fMiB/%.2fs] %s', $memoryUsage, $timeSpent, $message);
<?php });



Loop::addPeriodicTimer(5, function () {

    $memory = memory_get_usage() / 1024;

    $formatted = number_format($memory, 3).'K';

    echo "Current memory usage: {$formatted}\n";

});
<?php });



Loop::addPeriodicTimer($r, function () use (&$runs) {

    $kmem = round(memory_get_usage() / 1024);

    $kmemReal = round(memory_get_usage(true) / 1024);

    echo "Runs:\t\t\t$runs\n";

    echo "Memory (internal):\t$kmem KiB\n";
<?php Loop::addPeriodicTimer($r, function () use (&$runs) {

    $kmem = round(memory_get_usage() / 1024);

    $kmemReal = round(memory_get_usage(true) / 1024);

    echo "Runs:\t\t\t$runs\n";

    echo "Memory (internal):\t$kmem KiB\n";

    echo "Memory (real):\t\t$kmemReal KiB\n";
<?php     private function logEnd(float $startTime, SymfonyStyle $io, string $requestId): void

    {

        $duration = ceil((microtime(true) - $startTime) * 1000);

        $memoryUsed = ceil(memory_get_usage() / 1024 / 1024);



        $io->writeln([

            "END RequestId: $requestId",