Вход Регистрация
Файл: vendor/symfony/http-kernel/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php
Строк: 68
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentHttpKernelDataCollector;

use 
SymfonyComponentHttpFoundationRequest;
use 
SymfonyComponentHttpFoundationResponse;

/**
 * MemoryDataCollector.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class MemoryDataCollector extends DataCollector
{
    public function 
__construct()
    {
        
$this->data = array(
            
'memory'       => 0,
            
'memory_limit' => $this->convertToBytes(ini_get('memory_limit')),
        );
    }

    
/**
     * {@inheritdoc}
     */
    
public function collect(Request $requestResponse $responseException $exception null)
    {
        
$this->updateMemoryUsage();
    }

    
/**
     * Gets the memory.
     *
     * @return int     The memory
     */
    
public function getMemory()
    {
        return 
$this->data['memory'];
    }

    
/**
     * Gets the PHP memory limit.
     *
     * @return int     The memory limit
     */
    
public function getMemoryLimit()
    {
        return 
$this->data['memory_limit'];
    }

    
/**
     * Updates the memory usage data.
     */
    
public function updateMemoryUsage()
    {
        
$this->data['memory'] = memory_get_peak_usage(true);
    }

    
/**
     * {@inheritdoc}
     */
    
public function getName()
    {
        return 
'memory';
    }

    private function 
convertToBytes($memoryLimit)
    {
        if (
'-1' === $memoryLimit) {
            return -
1;
        }

        
$memoryLimit strtolower($memoryLimit);
        
$max strtolower(ltrim($memoryLimit'+'));
        if (
=== strpos($max'0x')) {
            
$max intval($max16);
        } elseif (
=== strpos($max'0')) {
            
$max intval($max8);
        } else {
            
$max intval($max);
        }

        switch (
substr($memoryLimit, -1)) {
            case 
't'$max *= 1024;
            case 
'g'$max *= 1024;
            case 
'm'$max *= 1024;
            case 
'k'$max *= 1024;
        }

        return 
$max;
    }
}
Онлайн: 0
Реклама