PHP Classes

Lighty

Recommend this page to a friend!

      PHP Classes blog  >  13 rules to optimize ...  >  All threads  >  Lighty  >  (Un) Subscribe thread alerts  
Subject:Lighty
Summary:expiring/caching
Messages:3
Author:Nuno Loureiro
Date:2007-08-31 12:31:11
Update:2008-01-08 23:29:48
 

  1. Lighty   Reply   Report abuse  
Picture of Nuno Loureiro Nuno Loureiro - 2007-08-31 18:29:07


Nice article.

About lighttpd and expiring/caching I would like to add a few things.

About expiring you can even do some more nifty things like:
$HTTP["url"] =~ "\.png$" {
expire.url = ( "" => "access 48 hours" )
} else $HTTP["url"] =~ "\.jpg$" {
expire.url = ( "" => "access 48 hours" )
} else $HTTP["url"] =~ "\.css$" {
expire.url = ( "" => "access 48 hours" )
}

ETags are on by default on lighttpd and if you run multiple servers, you should either disable it or configure it properly. The problem with disabling it is that you can't use mod_compress.

By default ETags are based on the inode of the files. If you have multiple servers most likely the files are not using the same inode numbers so the client's browser would need to cache N copies of the file, where N is the number of servers you run.

You can for example disable the inode usage for etags and enable mtime or size:
etag.use-inode = "disable"
etag.use-mtime = "enable"

You can read more about etags here:
developer.yahoo.com/performance/rul ...

You can read more about etags and lighttpd here:
trac.lighttpd.net/trac/wiki/etag.us ...
trac.lighttpd.net/trac/ticket/1209
trac.lighttpd.net/trac/wiki/Docs%3A ...

  2. Re: Lighty   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-08-31 20:02:02 - In reply to message 1 from Nuno Loureiro
Yes, I only set the expiry period to 10 days to satisfy YSlow. I tried a shorter period but it said it was not a far expiry period.

I also noticed that lighttpd was setting some odd integer numbers for the ETag headers. Now I understand that is the inode of the compressed cache file, which may be different in distinct cluster machines. Using the original file modification time should be safer. Thanks for the tips.

  3. Re: Lighty   Reply   Report abuse  
Picture of Grigori Kochanov Grigori Kochanov - 2008-01-08 23:29:48 - In reply to message 2 from Manuel Lemos
There is an even better HTTP server - nGinx.
It's somewhat similar to Lighttpd, but smaller and faster, especially with static data.
It may easily handle dozens of thousands of simultaneous connections, run as a load-balancer and reverse proxy, take data directly from memcached, etc.

I am using it instead of Apache, running PHP as fast-cgi on the unix socket.
The total memory consumption of Nginx+PHP+APC+MySQL is about 60 Mb, and it's a fully-functional server able to handle ~10-20 simultaneous connections normally.
This way a cheap VPS becomes a fully adequate way to run a site.

The only drawback is it's written by a Russian guy and original docs are in Russian. There are translations, though.