vega / memory-stat
一个简单的类,可以用来收集PHP脚本内存使用信息并打印所有信息。
dev-master
2020-05-14 15:16 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-27 12:17:04 UTC
README
#Memory Stat# 这是一个简单的类,可以用来收集PHP脚本内存使用信息并打印所有信息。如果你想在网页或命令行脚本中使用它,或者为网页和命令行脚本执行不同的功能。用法
使用composer require vegagame/memory-stat
安装最新版本
<?php use vegagame\MemoryStat; // Create new MemoryStat instance $m = new MemoryStat(true); // Example array $a = array(); $b = array(); $c = array(); // Fill array with for ($i = 0; $i < 10000; $i++) { $a[$i] = uniqid(); } // add first checkpoint $m->addCheckpoint('first checkpoint'); // get current memory limit from ini_get('memory_limit') echo 'Memory limit raw: '.$m->getMemoryLimitRaw().PHP_EOL; // 536870912 // get current memory limit formatted from ini_get('memory_limit') echo 'Memory limit: '.$m->getMemoryLimit().PHP_EOL; // 512M // get current memory usage echo 'Current raw: '.$m->getCurrentRaw().PHP_EOL; // 1835008 // get current memory usage formatted echo 'Current: '.$m->getCurrent().PHP_EOL; // 1.75M // Fill array for ($i = 0; $i < 30000; $i++) { $b[$i] = uniqid(); } // get peak Raw echo 'Peak raw: '.$m->getPeakRaw().PHP_EOL; // 6815744 // get peak usage formatted echo 'Peak: '.$m->getPeak().PHP_EOL; // 6.5M // add new checkpoint $m->addCheckpoint('second checkpoint'); // Fill array for ($i = 0; $i < 50000; $i++) { $c[$i] = uniqid(); } // get current raw information print_r($m->getInfoRaw()); /** * Array * ( * [time] => 1415461726 * [time_format] => 2014-11-08 16:48:46 * [total] => 536870912 * [current] => 15466496 * [increase_from_last_percent] => 55.93 * [total_percent] => 2.88 * * ) */ // get info formatted echo 'Get current information: '.$m->getInfo().PHP_EOL; // Memory Stat [2014-11-08 16:48:46] | Usage: 14.75M (2.88%) echo 'Get current information verbose : '.$m->getInfo(true).PHP_EOL; // Memory Stat [2014-11-08 16:48:46] | Memory Usage: 14.75M (2.88%) | Memory Peak: 14.75M | Memory Total: 512M | Increase from last checkpoint 55.93% echo 'Total information: '.PHP_EOL; echo $m->getTotal(true); // verbose version /** * Memory Stat [2014-11-08 16:48:40] | Info: Memory Stat Start | Memory Usage: 256K (0.05%) | Memory Peak: 14.75M | Memory Total: 512M | Increase from last checkpoint 0% * Memory Stat [2014-11-08 16:48:41] | Info: first checkpoint | Memory Usage: 1.75M (0.34%) | Memory Peak: 14.75M | Memory Total: 512M | Increase from last checkpoint 85.71% * Memory Stat [2014-11-08 16:48:43] | Info: second checkpoint | Memory Usage: 6.5M (1.27%) | Memory Peak: 14.75M | Memory Total: 512M | Increase from last checkpoint 73.08% * Memory Stat [2014-11-08 16:48:46] | Info: Memory Stat End | Memory Usage: 14.75M (2.88%) | Memory Peak: 14.75M | Memory Total: 512M | Increase from last checkpoint 55.93% */ // return all checkpoint array print_r($m->getTotalRaw());
版权
版权(c)2014 Denis Casanuova。有关详细信息,请参阅LICENSE。