Writing FCGI apps in Ruby, which are spawned from Apache or lighttpd, is straightforward enough. What I want to know is, what's the best way which a Ruby program can invoke other FCGI apps and send requests *to* them? And has anyone had success doing this? The application I have in mind is to make use of some existing perl code. I don't want to do rc = system("/usr/bin/perl", "foo.pl", *args) for every operation, as this spawns a whole perl interpreter each time. So what I wanted to do was to make minimal changes to the perl code so that it could accept multiple requests in a loop. I could just popen() each perl script and chat down stdin/stdout, but this limits me to one instance of this application per Ruby process. In practice there will be 10 or 20 different perl scripts that I want to persist, but each Ruby process will only invoke one or two of them before it finishes. However, if I use FCGI, I can have shared pools of Perl instances to be invoked by other Ruby processes as they come and go, and the size of each pool can be tuned statically or dynamically. This is very attractive. So how to achieve this? I could run those perl FCGI's under Apache, and then use Ruby's Net::HTTP to send requests to Apache which in turn sends them to those FCGIs. But I wondered if there was a more lightweight way to do this, formatting the FCGI requests and/or starting the pool of FCGI slave processes directly from Ruby. (Having said that, using HTTP as the glue, optionally with XMLRPC or SOAP running over it, would arguably be a "standard" solution) I can use the standalone program cgi-fcgi to start the pool members: http://www.fastcgi.com/devkit/doc/cgi-fcgi.1 So what I'm really looking for is something like the cgi-fcgi's "-bind -connect" option, to pass a CGI request down the socket, but written in or wrapped for Ruby. But I'm also open to suggestions for other ways to achieve what I'm trying to do. Thanks, Brian. P.S. Searching around, I did notice there's a webrick-fcgi module, which I thought maybe I could rip some code from. The website pointed to by http://raa.ruby-lang.org/project/webrick-fcgi/ is http://theinternetco.net/projects/ruby/webrick-fcgi/ This returns Content-Type: application/octet-stream, meaning the page does not display in a browser! Furthermore, if you try to download the source from http://theinternetco.net/projects/ruby/webrick-fcg... you get an HTML page rather than a tarball. So I can't download it, and I imagine it's unlikely that many people are using it. $ telnet theinternetco.net 80 Trying 126.96.36.199... Connected to theinternetco.net. Escape character is '^]'. GET /projects/ruby/webrick-fcgi/ HTTP/1.0 Host: theinternetco.net HTTP/1.0 200 OK Connection: close Content-Type: application/octet-stream <<<<< ! ETag: "2004059686" Accept-Ranges: bytes Last-Modified: Sat, 11 Jun 2005 22:35:45 GMT Content-Length: 582 Date: Thu, 01 Feb 2007 12:01:21 GMT Server: lighttpd/1.4.13 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>webrick-fcgi</title> <link rel='Stylesheet' href='../../site.css' type='text/css' /> </head> <body> <h1>webrick-fcgi</h1> <h2>Abstract</h2> <p>webrick-fcgi is a WEBrick-compatible API for the FCGI library.</p> <h2>Downloads</h2> <p>Version 0.1.0: <a href='webrick-fcgi-0.1.0.tar.gz'>webrick-fcgi-0.1.0.tar.gz</a></p> <h2>Documentation</h2> <p>Version 0.1.0: <a href='webrick-fcgi-0.1.0/doc'>rdoc</a></p> </body> </html> Connection closed by foreign host.
on 2007-02-01 13:21