Forum Moderators: coopster

Message Too Old, No Replies

What exactly "memory get usage" outputs?

On some uncertainty of memory usage estimation in PHP

         

alsid

9:06 am on Oct 23, 2010 (gmt 0)

10+ Year Member



Dear gurus, could you explain if possible what exactly "memory_get_usage" and "memory_get_peak_usage" functions output?

What I mean?

I mean it displays only memory usage during the CURRENT page processing by PHP engine? Or memory consimed by the WHOLE PHP engine processing not only the current website page, but also 1) other pages for other users for this website 2) pages from my other websites at this virtual hosting?

Thank You.

enigma1

9:58 am on Oct 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By default it returns the current script that runs. There is a parameter since 5.2 to get the usage for the system. It's all documented for the functions in php.net

alsid

10:33 am on Oct 23, 2010 (gmt 0)

10+ Year Member



enigma1, thank you for your reply.

Of course
[php.net ]
was the first place I look into. So as other places.

But there are no statements clarifying my question absolutely.

Could you probably point me to the right place?

Do you mean $real_usage parameter of "memory_get_usage()"?

At php.net we read:
$real_usage: Set this to TRUE to get the real size of memory allocated from system. If not set or FALSE only the memory used by emalloc() is reported.

"real size of memory allocated from system" - it is unclear - it means allocated from system for the current script that runs (current page generation) OR for the whole scripts on my account at virtual hosting?

penders

12:09 pm on Oct 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By default it returns the current script that runs. There is a parameter since 5.2 to get the usage for the system.


AFAIK it always returns the memory used (or allocated) from the system to the current script (page being processed) for the current visitor. And this is what the memory limits in php.ini refer to. I don't think there is any simple way, in PHP, to monitor the usage by all concurrent visitors (other pages) on your account, and especially other websites on the virtual host, unless you had some kind of server-side tool monitoring memory usage?

The $real_usage parameter allows you to check the actual memory used by your script. I'm guessing that when your script runs, emalloc() will allocate chunks of memory that it thinks will be reqd. Your script may not actually require all of this allocated memory (real_usage), or it may require more, in which case emalloc() will allocate another chunk (NB: this is how I think it works). If you monitor memory_get_usage() throughout the course of your scripts, this appears to be what's happening. memory_get_usage(false) increases in blocks. memory_get_usage(true) - real usage - is always less than memory_get_usage(false) - allocated usage. However, I assume that the allocated usage determines if you run out of memory or not!

alsid

2:38 pm on Oct 23, 2010 (gmt 0)

10+ Year Member



penders, thank you. According to majority opinion :) it really looks like it returns the memory used for the current script...