For a little private project, which makes extensive use of caching, I recently checked, where I could get gather some more performance from. Kore told me, that Lighttpd ships all of the pages of one of his projects in about 0.001 seconds, while mine still took 0.004 seconds on Apache. After some tracing I found the actual point of problem: The echo of the final output, which took most of the time. I tried to run the same project on Lighttpd and guess what: There were the 0.001 seconds.
After this adventure, I made a little benchmark between Apache (with mod_php) and Lighttpd (with fastcgi). I took 3 files of different sizes: a small one, with about 30kb, 1 medium size (about 70kb) and a large image (about 280kb). The only thing my PHP script does is reading the file using file_get_contents() (this part is not measured) and echoing it to the browser (this part is measured). The results, in seconds, are (average values from 1000 script runs):
Files | Apache | Lighttpd |
Small | 8.74919891357E-05 | 6.94532394409E-05 |
Medium | 0.000167278051376 | 0.000110051393509 |
Large | 0.00403597259521 | 0.00102773714066 |

Note: For this image I multiplied the "medium" and "small" numbers with 10!
I found this results quite impressive and it confirmed my usage of Lighttpd, although I wondered, where this may come from. A discussion in our usergroup brought up the thesis, that fastcgi uses shared memory to transfer data, while mod_php seems to use something else. I actually have no clue if this is correct, but it sounded valid to me. Maybe someone can enlighten us?
If you liked this blog post or learned something, please consider using flattr to contribute back: .
Fields with bold names are mandatory.
TLJ
You should try the same benchmark on apache w/fastcgi too.
Link to commentI have a setup with seperate servers for web and PHP. Recently I replaced lighty with a really small and minimal compile of Apache 1.3 running PHP as FastCGI, with the exact same config as lighty had done.
To my big surprise, Apache is actually a lot faster. And it doesn't drop 10-30 reqs/sec, like Lighty had a tendency to do.
Tom
Hm, what exatly did you measure and how? For me it looks like some wrong measurment method....
Link to commentIlia Alshanetsky
The slowdown may have to do with the way data is transmitted. Both PHP and Apache buffer output and when the buffers mismatch and/or are too small you can lose a lot of speed.
Link to commentFor the sake of a test I'd recommend setting PHP's output buffering to roughly a page size and in Apache setting buffer to page size + 4kb (to allow for headers & misc overhead).
Jan Kneschke
FastCGI is purely socket based. It either uses TCP/IP or Unix Domain Sockets.
Link to commentIf you care about really small setup costs for a request, take a look at http://blog.lighttpd.net/articles/2006/10/08/reducing-requests-setup-costs
or http://jan.kneschke.de/projects/lua/
Damien
I don't have any clue about this phenomenon, but it could be very interesting to compare PHP4 in CGI (with and without fastcgi) in Apache environnement with PHP4 in Lighttpd in order to see where the problem is.
Link to commentChristian
Yeah, this is kinda impressive.
Link to commentIsn't there a possibilty to use php with apache via fastcgi?
Would be nice to get times for this, too.
Greetings
Brian Moon
Interesting. I found the opposite results when testing lighttpd vs. apache for caching large output. The HTML on our front page at dealnews.com can approach 120k. At those sizes, I found Apache must faster. It did take about 20 trips to the lighttpd support forums to get my config right as it seems it does not come configured very well IMO.
Link to commentSee http://forum.lighttpd.net/topic/322
Alexandre Girao
The main difference between apache and lighttpd is the serving model, lighttpd is event-driven and apache is threaded or pre-forked, you can read more information here:
Link to commenthttp://www.kegel.com/c10k.html
instore sampling
I really love reading your blog. It was very well authored and easy to understand. Unlike additional blogs,I have read which are really not good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he enjoyed it as well!
Link to commentbeauty tunics
I want to write a quick note to express my thanks. I’m really impressed by a blog unique and perfectly chosen and organized!
Link to comment