Picon

multiple connections to a fastcgi server

Hello,

I want to build a fast cgi server application which can handles long
polling calls. There should be only one process of this fast cgi app
which handles all incoming requests.
I wrote an app which is similar to the threaded.c example in the fast
cgi sdk. (http://www.fastcgi.com/devkit/examples/threaded.c)
Before responding, my app will wait a certain time after an incoming
request. (For testing I only put a sleep() call above
FCGX_FPrintF(...) in threaded.c).
I tested with Lighttpd und nginx and got the same result: The second
call is blocked until the first one is finished. I think the method
FCGX_Accept_r(&request); blocks until FCGX_Finish_r(&request); is
called.
Does anyone has a running multithread fastcgi app?

Thanks
Marc
Dean Banks | 5 May 2011 04:25
Picon

Re: multiple connections to a fastcgi server

Hi Marc,

I have a multithreaded fastcgi app that handles multiple requests as 
expected.  I modeled it after the threaded.c example in the SDK as well, 
though I changed to make the FCGX_Accept_r() call non-blocking  (mostly 
so that I could gracefully exit the whole app with SIGINT).

In your application, FCGX_Accept_r() blocks until an incoming request is 
passed from the webserver to your application.  Provided that you have a 
separate context for each thread (as the example shows), you should be 
multithreading properly.  One way to test this might be to use two 
threads, but only sleep if the thread number is 0.  If you open two 
browsers, you should be able to make a request to the first (held up by 
sleep()) and still get active responses from the second broswer (the 
available thread).

Please feel free to post any other questions.  This list is sleepy, but 
has lots of helpful folks lurking.

Cheers,

Dean

Gmane