Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running apache with a worker MPM and php with fastcgi.

the following are my mpm limits:

StartServers         5
MinSpareThreads      5
MaxSpareThreads      10
ThreadLimit          64
ThreadsPerChild      10
MaxClients           10
MaxRequestsPerChild  2000

I've also setup my php-cgi with the following:

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

I'm noticing that my average php-cgi process is using around 200+mb of RAM, even as soon as they are started. However, my php memory_limit is only 128M.

How is this possible, and what can I do to lower the php-cgi memory consumption?

share|improve this question
    
You're confusing memory with RAM. They're using 200MB of memory, not RAM. Memory is a nearly free resource, since the system can create tons of it at nearly zero cost. –  David Schwartz May 23 '12 at 6:37

2 Answers 2

There are instances where PHP can exceed the configured memory limit (memory malloc'ed directly in extensions) however I suspect this may not be the case.

I'm noticing that my average php-cgi process is using around 200+mb

How did you measure this? Most of the TXT segments will be shared - so actual memory usage is a lot less than what you'd see in the /proc filesystem or in ps/top. While you could try parsing the output of lsof, in practice I find it much more sensible to step back a bit and look at the number of requests in progress (e.g. from the number of connected sockets) and comparing this with the free memory reported (less buffers/cache).

share|improve this answer

Memory limit in PHP is the internal memory limit - i.e. that's the amount that the engine would allow the user script to allocate through it's private allocator. But besides that there's memory that is allocated by the engine for its internal needs, which is not always counted towards the limit (some of it is, but not all of it), the memory being allocated by libraries, etc. So expect real memory usage to be slightly bigger than memory_limit setting.

Also, as mentioned above, some of the figures reported by tools are memory allocated for the code, stack, OS I/O buffers, shared memory between libraries, etc. so look closer into which figure you are checking.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.