views:

223

answers:

1

I am using xdebug to trace some code to see how much memory it is using, but at the start of the trace, it is using around 560224 bytes of memory. Is this normal? This is before any code is executed.

Edit: I should have clarified; this is not what I am trying to optimize. I just noticed it and wanted an explanation.

+2  A: 
# php -r 'var_dump(memory_get_usage());'
int(75880)
# php -r 'var_dump(memory_get_usage());'
int(75880)
# php -r 'var_dump(memory_get_usage());'
int(75880)

Two interesting things here: a bare-bones "script" is taking 76k on the command line, and it's consistently doing so.

# php -r 'var_dump(memory_get_usage()); echo "";'
int(76016)
# php -r 'var_dump(memory_get_usage()); echo ""; echo "";'
int(76160)

Adding code adds to memory use. No surprise -- the parsed code has to go somewhere.

So: the memory use you're seeing is all your code, and anything else that gets built at start time. Remember, by the time your first line of code runs, PHP's already parsed much, if not all of your code. (any dynamic includes or autoloads may cause some parsing to happen later)

Trying to cut this down may be futile, by and large, although you might want to look at avoiding any unnecessary includes. That's just a good idea anyway.

Frank Farmer