In my project I use my own framework, and sure I use my own logging time and memory. Now I found that my memory usage statistics different in different environments. Here I mean two environment: local Windows and production VPS Fedora.
Here is the logger view:
<style>
div.lt-timer {
opacity: 0.5; background: #FFF; color: #777; border-radius: 5px; border: 1px solid #CCC;
font-size: 0.85em; position: fixed; max-width: 300px; max-height: 600px; overflow: auto;
bottom: 10px; right: 10px; padding: 5px;
}
div.lt-timer h4 { text-align: center; font-weight: 700; }
</style>
<div class="lt-timer">
<h4><?php echo $timer->getName(); ?></h4>
<?php echo nl2br(implode('', $timer->getPoints())); ?>
<h4>Total used memory: <?php echo round(memory_get_usage() / 1024, 2); ?> KB</h4>
</div>
Everything is fine, except this line, which gives difference:
<h4>Total used memory: <?php echo round(memory_get_usage() / 1024, 2); ?> KB</h4>
On Windows I’ve got about 598 KB, but for the same request I have 2976 KB on VPS Fedora.
I’ve also have tested for same test.php files containing this:
<?php
$a = 999;
$b = 999;
$c = 999;
echo memory_get_usage();
?>
And that’s what I got:
Local machine (Windows): 329280
Production machine (Fedora): 633392
Does eAccelerator or xCache could affect this statistics? Or where I’m wrong?
As of PHP 5.2.x, the memory_get_usage() function has a parameter.
According to php.net, $real_usage is:
Additionally some sources say PHP needs to be loaded as a CGI in Apache to correctly get memory usage by process id using getmypid().