PHP FastCGI, Lighttpd and Memory Leaks

/php-fastcgi-lighttpd-and-memory-leaks 2009-12-18T16:22:43+00:00

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

Copyright © 2005 - 2021 Colin Seymour All rights reserved. Privacy Policy.
Check out the feed if you do the RSS/Atom thing.