iQwerty wrote:
No memory leak over here, have fast-cgi and xcache running.
Actually, the latest version (1.4.20, or 1.4.19-5 if you prefer the Debian/Ubuntu binary) still leaks memory in one particular case. If you allow users to download large files through a PHP script, and the script uses readfile() to send the file to the user, lighttpd caches the entire response in RAM and never releases it afterwards. So if somebody is downloading a 50MB file with PHP readfile(), your lighty process grows by 50MB. If 10 users simultaneously download a 50MB file, your lighty process grows by 500MB. Not good! I personally ran into this problem a few weaks ago, and it wasn't pretty.
But there's an easy workaround for this particular memory leak. Instead of using readfile() in your PHP script, you can have your PHP script send a custom HTTP header called X-LIGHTTPD-send-file. Lighttpd will intercept this header and send the named file to the client on your behalf, modifying the value of Content-Length accordingly. Then the custom header will be removed, so your clients will never know the absolute path of the file on your server. This method performs much better -- after all, lighttpd is designed to quickly send large static files -- and it doesn't leak memory at all (at least in the latest version). I've been using it to serve large files since the little incident a few weeks back, and lighttpd+PHP could serve 25GB of large media files in a day without any memory leak.
This is how you do it in PHP:
Code:
header('X-LIGHTTPD-send-file: /absolute/path/to/file']);You also need to enable send-file in your FastCGI configuration. Notice the "allow-x-send-file" directive below.
Code:
fastcgi.server = ( ".php" =>
((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 1,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "8",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable",
"allow-x-send-file" => "enable"
))
)
And if you're still worried about undocumented memory leaks, here's another workaround. Run the following command every now and then, preferably using cron.
Code:
ps -C lighttpd -o rss=
This will return a single integer value representing the size (in kilobytes) of your lighttpd process. Pass the value to a little script written in your favorite scripting language. From your script, restart lighttpd if the value exceeds a preset threshold.
But then, I'm seriously considering a move to nginx

The English documentation has gotten a lot better these days, and the rewrite functionality also seems much closer to that of Apache!