tags:

views:

54

answers:

1
+2  Q: 

PHP Memory Limit

Hello all,

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.

+2  A: 

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.

VolkerK
@VolkerK - thank you very much that was the explanation I needed!
Abs