4

I have a small question, when we set the memory_limit for PHP I understand that it will use that integer as the maximum memory allowed for a script to consume.

Does this mean if I set the maximum at 64MB and my script only needs 12MB that it will make use of the full 64MB just because its allowed?

I ask because I notice some of my scripts although make use of 12MB (found out using get_memory_usage) but the httpd process itself is getting near the 64MB mark even though that is the only script running! Btw, I am not having a memory leak issue.

Is it also the case that other process it spawns i.e. CMD will be added to the httpd processes overall memory usage?

Thanks all for any help on clearing this up for me.

4
  • 1
    (sidenote) To get the maximum memory a script consumes during it's lifetime use memory_get_peak_usage at the end of the script. Commented Aug 17, 2010 at 9:55
  • "but the httpd process itself is getting near the 64MB" - where do you see that (which program do you use) and exactly which value do you refer to? Commented Aug 17, 2010 at 9:59
  • @VolkerK - I am on a windows machine so I use Task Manager on the Process Tab under the Memory column. Commented Aug 17, 2010 at 10:06
  • @Gordon - thanks I will try that. But the strange thing is that when any script is run it jumps to near enough 64,000KB through the scripts life and then comes back down. Commented Aug 17, 2010 at 10:08

1 Answer 1

5

PHP's memory_limit only takes memory into account that is handled by the Zend Engine's memory manger (see Zend/zend_alloc.c) and this manager does not allocate the amount set via memory_limit "pre-emptively" (though it allocates new memory in segments). Not everything "within" PHP is handled by the memory manager, but the majority is. Other processes spawned by your instance of php do not "inherit" the memory manager. Therefore their memory consumption does not count against memory_limit.

What you saw in the task manager is (most likely) the working set of the httpd process. That includes the memory allocated by php (handled by the memory manager or not) if it is installed as an apache module. But also anything else of the httpd that is currently in physical memory. But it does not include the amount of memory allocated by spawned processes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.