Forum

gzip from fastCGI

Simon D
25 July 2012, 13:18
Hi all,
I'm looking at using Hiawatha on a dedicated web server and using fastCGI for performance reasons. I'm not 100% if that's the route to take but that's the plan.

I've two questions.

1) I want to compress as much of my responses as possible, so how can this be done with fastCGI? I assume this can be done because you can set PHP to do this, so do you just set headers and return the compressed data? How do you do this?

2) Can someone give me a breakdown of the process and threading model of Hiawatha, and how this works with fastCGI daemons. I don't know exactly how the connections are handled, how they're distrubuted, and how best to organize my code (and how many daemons to run). I tried to examine the source, but my dev environment was not happy? The code was using struct members that were not in the structs, and I quickly got lost. Do I run single thread deamons, or should they use threading to maximize throughput?

Thanks for any pointers.
Simon.
Hugo Leisink
25 July 2012, 23:08
1) In php.in, set "zlib.output_compression = On" and "zlib.output_compression_level = 6". That should do it.

2) Single process and a thread for each client connection. This has nothing to do with how FastCGI works. A Hiawatha thread connects to the FastCGI daemon, sends the request, recieves the response and closes the connection. How many daemons to run depends on how quickly a single requests is handled by the FastCGI daemon and how many requests per time interval you receive. A simple calculation will tell you how many FastCGI daemons you need when you don't want a Hiawatha thread to wait for a FastCGI daemon to finish its current request.
Simon D
26 July 2012, 14:06
Thanks Hugo, answer 2 was a help.

However my first question was how do I go about replying with compressed data from a FastCGI app, not PHP. I did read that you could set PHP to do this, and PHP is run as a FastCGI extention to the server, so it can be done. What I'm after is how it's done.

The HTTP response needs headers and content. I'm guessing I need to return some headers and the compressed data, and this would be appended to any headers that Hiawatha produces.

Is that right?

Thanks for your help, Simon.
Hugo Leisink
26 July 2012, 19:04
First, you need to be sure that the browser can handle compressed data. It can be found in the "Accept-Encoding" HTTP header. If 'gzip' is part of the value, the browser supports GZIP compression. In that case, you need to set the HTTP header "Content-Encoding" to "gzip" and gzip the request body of your response.
Simon D
26 July 2012, 20:21
That's just what I needed to know, thankyou Hugo.

Simon.
This topic has been closed.