note 98734 added to function.memory-get-peak-usage
| From: | kn33ch41 at osu1 dot php dot net | Date: | Sat, 03 Jul 2010 08:10:14 +0000 |
| Subject: | note 98734 added to function.memory-get-peak-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170678@lists.php.net to get a copy of this message | ||
It should be noted that this function is more accurate for measuring the total memory usage of a PHP
script than memory_get_usage(), which will instead only return the amount of memory being used at
the time it was invoked.
If this difference is still unclear just remember that as a PHP script builds its rendered version
it uses varying amounts of memory per microsecond. Retrieving the peak memory usage will simply tell
you that at one point the script required the use of "this much" memory in the
microseconds that it took to build the page, which is certainly the more accurate number if your
intention is to determine how much memory a script uses. It's useful to know this particularly
when working in a shared environment with limited resources.
Furthermore, most standard installs of PHP limit memory usage per script to 8MB or 16MB in some
cases; hosts tend to enforce such defaults. If you note the peak memory usage of your script is 7MB
don't immediately worry or exacerbate the worry by doing a superficial calculation to tally how
much memory the given page will consume for 1000 visitors, for example. Remember this very important
fact: such peak script memory consumption is on the level of microseconds. The only way that
particular script will require a dedicated 7000MB of memory, given our example, is if all 1000
visitors visited the page at the very same microsecond.
Is 8MB a lot for a script to consume? Is your page too expensive resource-wise if it does require a
max of 8MB at one point? To answer either: not necessarily. An 8MB default was established precisely
because it has been defined as a somewhat reasonable ceiling. My intent in stating this is to
alleviate any benchmark or performance woes one may experience, particularly those who are new to
the language. For example, if you're doing a simple database query or looping through
relatively small arrays of data and you notice the script memory consumption has reached that
ceiling, then, and only then, should you be alarmed; however, if you're performing multiple
database queries with complex table joins or looping through huge arrays of data, then expect the
peak memory consumption to be high, which in this case is reasonable. There's no absolute
answer for determining unreasonable or average script peak memory consumption, but there are answers
relative to the function or purpose of a given script.
A good article on the two functions mentioned is located at http://www.ibm.com/developerworks/opensource/library/os-php-v521/
Good day!
----
Server IP: 69.147.83.197
Probable Submitter: 216.252.93.121
----
Manual Page -- http://www.php.net/manual/en/function.memory-get-peak-usage.php
Edit -- https://master.php.net/note/edit/98734
Del: integrated -- https://master.php.net/note/delete/98734/integrated
Del: useless -- https://master.php.net/note/delete/98734/useless
Del: bad code -- https://master.php.net/note/delete/98734/bad+code
Del: spam -- https://master.php.net/note/delete/98734/spam
Del: non-english -- https://master.php.net/note/delete/98734/non-english
Del: in docs -- https://master.php.net/note/delete/98734/in+docs
Del: other reasons-- https://master.php.net/note/delete/98734
Reject -- https://master.php.net/note/reject/98734
Search -- https://master.php.net/manage/user-notes.php