I recently purchased a 1/4GB Joyent Accelerator account (aka zone) and thought as I’ve got full control of what I run, I’ll try the Lighttpd (1.4.22) and PHP FastCGI (5.2.9) combination for my website hosting. Whilst this worked great and performance was pretty impressive, I’m not too impressed with the memory consumption of the PHP FastCGI processes.
My accelerator is limited to 256MB and I was finding I was soon reaching this limit with each php-cgi process consuming at least 20MB, often with one consuming over 100MB!!!. At one stage this got so bad that I couldn’t even login so had to get Joyent to reboot my zone.
I’ve tried several things to try and reduce the memory usage including reducing the number of child processes (PHP_FCGI_CHILDREN) to 4 and lowering the number of requests for each process (PHP_FCGI_MAX_REQUESTS) down to 400 and the problem continued. I’ve also tried using OpenSolaris resource controls and whilst this stops the entire zone’s memory from being hogged by the php-cgi processes, it doesn’t stop the copious amounts of memory being munched by these processes.
For those interested, my fastcgi.server config section is as follows:
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/opt/local/bin/php-cgi",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "400"
),
"broken-scriptfilename" => "enable"
)
)
)
max-procs is set to 1 as I was using eAccelerator.
Now, I know I can setup a cronjob to kill off these large processes on a regular basis, but this isn’t a solution: it’s a workaround or more precisely a hack.
So my question is: how on earth do people run with Lighttpd and PHP FastCGI in a constrained production environment without resorting to hacks to limit what appears to be php-cgi leaking memory?
I’ve resorted to using Apache and mod_php and as expected, memory usage has been perfectly acceptable for over a week now (Lighty/PHP FastCGI ran out of memory at least once a day).
2 Responses to “PHP FastCGI, Lighttpd and Memory Leaks”
Speak Your Mind 
Search
Related Entries
- Experimenting with Wordpress Option Autoloading
- Wordpress is a Memory Hog
- HOWTO: Fix “ORA-27102: out of memory” Error on Solaris 10
- Links for 20 Feb 2008 - 1 Mar 2008
- Links for 21 Mar 2008 - 25 Mar 2008
- Update on Wordpress Autoload Option Experimentation
- ZFS 2GB Swap
- Links for 12 Dec 2008 - 24 Dec 2008
- Happy Birthday IBM Compatible PC
- Sun Back In Supercomputers


php fastcgi leaking? I don’t think so!
) and was told it was a feature.
It’s just that PHP never returns memory to the system.
I’ve filed a bug years ago (when php4 was new
So if one script takes up loads of ram, this process keeps the ram for the next time.
The solution is to renew the PHP (or Apache in module config)processes regularly, eg: reduce PHP_FCGI_MAX_REQUESTS.
optimize memory usage. unset variables when no longer needed,…
Also, use fewer built-in extensions and prefer to load them dynamically.
But a small php5.2.x cgi engine is about 8.8MB (coolstack x86) anyway.
Michel
Thanks Michel. I sort of discovered this may have been PHP rather than FastCGI from the various comments I found, however given that PHP 5 is meant to have a new memory manager, you would have thought they’d coded in some sort of efficient garbage collector.