[Xitami] Persistent CGI, anyone interested ?

Marcio Marchini xitami@lists.xitami.org
Mon, 26 May 2003 14:55:04 -0400


Hi,

	As some of you know, if you want a web app integrated with your web server you
have to either make it into a CGI program that is loaded/unloaded everytime your
URL is hit, or you must have a persistent (always running) server that sits
behind Xitami (or Apache) so that this process is sped up.

	As you know, doing this under Apache is specific to Apache, and doing this for
Xitami is specific to Xitami too (LRWP). If you use Java servlets then you are
fine because both Apache and Xitami can run servlets in a persistent manner (the
Sokrates folks have implemented the LRWP for you).

	Now, if you want to do something in another language (say Python) and want to
have the interpreter pre-loaded and already running, a portable alternative
would be Fast CGI
(http://www.fastcgi.com/devkit/doc/fastcgi-whitepaper/fastcgi.htm), but that
involves supporting their protocol too, which is not super simple.


	What I did was a portable, small executable, that implements a persistent CGI
in the simplest possible way. You use it like this:

	http://localhost/cgi-bin/pcgi


	The executable is launched, and it reads a cfg file that tells what host & port
the actual server is running. Then it forwards all the CGI environment variables
to it, and waits for bytes from it and forwards these to the original requestor.
So, it acts like a middle-man. Like this:


   HTTP          +-------------+
+---------------+
<--------------> | web server  | <---> (pcgi is exec'ed) <----> |  your server
|
                 +-------------+
+---------------+



	The idea is that pcgi is a lot faster to launch for every URL that is
requested, at least faster than your whole web app. That is so because pcgi.exe
is just 58KB. So, this allows it to be loaded fast, and then you can have your
persistent server always running, behind either Apache or Xitami.

	Anyway, if you are interested in using this please contact me. The source code
is Open Source, and compiles under Linux, Windows, etc. In fact it will compiler
under all platforms supported by SmartEiffel
http://smarteiffel.loria.fr/index.html

	Here's an example output of a persistent web app that simply echo's the env
vars back, if you use the URL http://localhost/cgi-bin/pcgi?foo=bar


AUTH_TYPE=
CONTENT_LENGTH=0
CONTENT_TYPE=
GATEWAY_INTERFACE=CGI/1.1
HTTP_ACCEPT=*/*
HTTP_REFERER=
HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461;
YComp 5.0.0.0; .NET CLR 1.0.3705)
PATH_INFO=
PATH_TRANSLATED=C:/Xitami/webpages
QUERY_STRING=foo=bar
REMOTE_ADDR=127.0.0.1
REMOTE_HOST=127.0.0.1
REMOTE_USER=
REMOTE_IDENT=
REQUEST_METHOD=GET
SCRIPT_NAME=/cgi-bin/pcgi
SERVER_NAME=localhost
SERVER_PORT=0
SERVER_PROTOCOL=HTTP/1.1
SERVER_SOFTWARE=Xitami



marcio