Php-cgi memory usage higher than php’s memory limit

apache-2.2PHPphp-cgi

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?

Best Answer

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).

Related Topic