Reputation: 2937
I just noticed - by calling memory_get_peak_usage() on an 'empty' php file, using php-fastcgi and NGINX, the result is ~120KB of memory
<?php
print_r(memory_get_peak_usage());
?>
Does PHP really need that 'much' memory for every call, or does that only happen for the first call (initializing something I guess) and then every consecutive call needs less Memory?
I'm asking, because I'm kind of surprised that an empty file already uses up 140KB - guessing that a couple of classes, functions and arrays will push that number up quite fast.
And yeah, I know that this probably counts as premature optimization, but I'm really curious about knowing where those 120KB are coming from, and if there's a way to minify that cost per call.
Upvotes: 2
Views: 329
Reputation: 4108
The first comment on the php.net docs page states:
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.
http://php.net/manual/en/function.memory-get-peak-usage.php
And the default allotment per connection is between 8-16mb, so you're still way below that.
For what it's worth, doing the same thing on my server yields 650kb, so you're already doing better than me ;)
Upvotes: 2
Reputation: 154663
That's nothing compared to a real app which takes between 5 to 15 MB per call. I'm not sure where the 120KB are coming from but I suppose from loaded extensions, backtraces, logs...
Do you have APC or any other accelerator active?
Upvotes: 2