[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\HttpKernel\DataCollector; 13 14 use Symfony\Component\HttpFoundation\Request; 15 use Symfony\Component\HttpFoundation\Response; 16 17 /** 18 * MemoryDataCollector. 19 * 20 * @author Fabien Potencier <fabien@symfony.com> 21 */ 22 class MemoryDataCollector extends DataCollector 23 { 24 public function __construct() 25 { 26 $this->data = array( 27 'memory' => 0, 28 'memory_limit' => $this->convertToBytes(ini_get('memory_limit')), 29 ); 30 } 31 32 /** 33 * {@inheritdoc} 34 */ 35 public function collect(Request $request, Response $response, \Exception $exception = null) 36 { 37 $this->updateMemoryUsage(); 38 } 39 40 /** 41 * Gets the memory. 42 * 43 * @return int The memory 44 */ 45 public function getMemory() 46 { 47 return $this->data['memory']; 48 } 49 50 /** 51 * Gets the PHP memory limit. 52 * 53 * @return int The memory limit 54 */ 55 public function getMemoryLimit() 56 { 57 return $this->data['memory_limit']; 58 } 59 60 /** 61 * Updates the memory usage data. 62 */ 63 public function updateMemoryUsage() 64 { 65 $this->data['memory'] = memory_get_peak_usage(true); 66 } 67 68 /** 69 * {@inheritdoc} 70 */ 71 public function getName() 72 { 73 return 'memory'; 74 } 75 76 private function convertToBytes($memoryLimit) 77 { 78 if ('-1' === $memoryLimit) { 79 return -1; 80 } 81 82 $memoryLimit = strtolower($memoryLimit); 83 $max = strtolower(ltrim($memoryLimit, '+')); 84 if (0 === strpos($max, '0x')) { 85 $max = intval($max, 16); 86 } elseif (0 === strpos($max, '0')) { 87 $max = intval($max, 8); 88 } else { 89 $max = (int) $max; 90 } 91 92 switch (substr($memoryLimit, -1)) { 93 case 't': $max *= 1024; 94 case 'g': $max *= 1024; 95 case 'm': $max *= 1024; 96 case 'k': $max *= 1024; 97 } 98 99 return $max; 100 } 101 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |