Memory_Get_Usage() Unnatural memory usage.

Irgendwelche Probleme mit XAMPP für Windows? Dann ist hier genau der richtige Ort um nachzufragen.

Memory_Get_Usage() Unnatural memory usage.

Postby Jumpy09 » 13. May 2011 23:34

Alright, I have finally after a few days of testing and trying to find a problem with my code tracked this problem down to my Xampp Installation.

Xampp Build: 1.7.5 Beta
Operating System: Windows 7 (All Updates)
Processor: 2.5GHz Core 2 Duo
Memory: 4GB
Added: Alternate PHP Cache

My script reads 500+KB Used on Xampp, but only reads about 215KB on a server.

First of all: I understand that different set-ups will return different results, but when another Xampp set-up returns a lower result as with a Live Server, it comes to my attention that something isn't correct.
Second of all, I have tested it with the following script!

Code: Select all
<?php
$genStartMemory = memory_get_usage();
/*****
   Vladan's byteSize Function
   Found: http://www.phpfront.com/php/Convert-Bytes-to-corresponding-size-II/
*****/

function bytesConvert($size, $unit = NULL, $decimals = 2, $thousands_sep = ",")
{
   static $units = array('B', 'KB', 'MB', 'GB', 'TB');
   static $actual = 'B';

   $index = array_search($actual, $units);

   if (($unit == NULL && $size < 1024) || $unit === $actual || $index == sizeof($units)-1)
   {
      $decimals = ($size < 1024 && $actual != 'B' ? (int) $decimals : 0);

      $unit = $actual;

      $actual = 'B';
      
      return(number_format($size, $decimals, ".", $thousands_sep) . " " . $unit);
   }
   else
   {
      $actual = $units[$index+1];

      return(bytesConvert($size / 1024, $unit, $decimals,  $thousands_sep));
   }
}
$regUsage1 = bytesConvert(memory_get_usage() - $genStartMemory);

$someArray = array("Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array", "Array");

foreach($someArray as $key => $value)
{
   echo $key . " => " . $value . "\n";
}

echo "<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>
<p>Long</p>";

$regUsage2 = bytesConvert(memory_get_peak_usage() - $genStartMemory);
echo "1: $regUsage1<br />";
echo "2: $regUsage2<br />";
?>


Results:

Array / ForEach Alone: 65.78KB
Long Echo Alone: 5.21KB
Both Together: 431.70KB

Another XAMPP Install - Both: 65.59KB
Live Shared Server - Both: 51.94KB

I know that memory returns are going to be different depending on the system, what operating system used, hardware configuration.. There are a lot of factors, but something returning 350KB -> 380KB higher would be a bit unnatural.

Other than the APC, nothing is different than the initial install. I have modified the php.ini and httpd.conf files, but I don't believe either of them would cause a high return on memory usage.

I considered that APC may be a problem, but I took it off and restarted the server and my script ran up to 700+KB Memory Usage. So, I am wondering what may cause such a high return on memory_get_usage() with Xampp.
If anyone tries the test above which replicated my issue, you will see that the returns for both will be greatly lower than what it shows on my set-up. Tested from multiple locations, not just on the local computer.
I have XAMPP on a remote computer, and I am working on the server from my Desktop, so there is nothing active on the server computer other than XAMPP.
Jumpy09
 
Posts: 1
Joined: 13. May 2011 23:03

Return to XAMPP für Windows

Who is online

Users browsing this forum: No registered users and 44 guests