tags:

views:

258

answers:

2

How do I check if a FastCGI server is alive and running normally beyond just making a TCP connection?

I have a number of remote, stand-alone FastCGI servers. I want to monitor the FastCGI server itself to ensure its alive. Simply making a request of the web server is not enough as it will automatically route around a dead server.

Thanks!

+1  A: 

You can connect to FastCGI server and send control FCGI_GET_VALUES empty request. It should be supported by fastcgi server, the official libfcgi should support it.

See http://www.fastcgi.com/devkit/doc/fcgi-spec.html

Send to Socket following:

unsigned char buf[16] = { 1,9,0,0 ,0,0,8,0 , 0,0,0,0, 0,0,0,0};
// fcgi protocols = 1
// fcgi_get_values = 9
// padding  = 8 -- for some reason libfcgi expects non-empty body
// body -- empty 8 bytes.

You should get

unsigned char buf[8] = { 1, 10,0,0, 0,0,0,0 };
// fcgi_protocol = 1
// fcgi_get_values_response = 10

You should actually chek you get 10 as response.

Artyom
Thanks for answering. Is there a library I can use to speak to a FastCGI server rather than coding up something to speak a binary protocol? C, PHP, Ruby or Perl preferred but I'll take anything.
Schwern
Added simple example how to implement
Artyom
Thanks for the explanation.
Schwern
+2  A: 

You can use cgi-fcgi program that comes with FastCGI development kit. On Debian-like systems, and in macports, program is included with libfcgi package.

My script with cgi-fcgi invocation is published at http://gist.github.com/209446

Maciej Pasternacki
Excellent, thank you!
Schwern