[plt-scheme] Faster CGI

From: Eddie Sullivan (eddieSull at hotmail.com)
Date: Wed Dec 10 14:47:48 EST 2008

If anybody's interested, I've attached a simple wrapper for the FastCGI C 
library I hacked up when I was first learning Scheme. As a warning, it's 
probably not the best written code, and it's definitely incomplete, but it 
may be a starting point.

I originally wanted to code up the FastCGI protocol from scratch, but the 
networking libraries provided with PLT are not low-level enough (I needed 
some way to determine what type of port stdin was, to differentiate between 
CGI and FCGI).

Anyway, you should be able to run the same code under FastCGI and regular 
CGI. The function "fcgi-loop" takes a no-parameter-function as parameter, 
and calls it repeatedly (for FCGI) or once (for CGI). In the case of FCGI, 
current-input-port, current-output-port, and current-error-port are 
parameterized for the FCGI versions of those ports. It also tries to fake 
out the environment variables, but that part's a little hacky.

The attached fcgi-cgi.scm shows an example use. It's a (F)CGI script that 
multiplies the two request parameters num1 and num2.

Hope it helps.
-Eddie Sullivan

> From: "Jay McCarthy" <jay.mccarthy at gmail.com>
> Subject: Re: [plt-scheme] Faster CGI
> Ah, I understand now. Yes, I would recommend writing something like a
> FastCGI wrapper, I imagine that the protocol is fairly simple, if
> you'd like me to look it over and give any tips on controlling
> resources (i.e., with custodians), I'd be happy to.
> Jay
> On Mon, Dec 8, 2008 at 8:27 PM, Henk Boom <lunarc.lists at gmail.com> wrote:
> > 2008/12/8 Shriram Krishnamurthi <sk at cs.brown.edu>:
> >> Yes, that's correct.  But the point is that they make it much more
> >> friendly to use continuations if you so desire (ie, if you haven't
> >> used the server w/ continuations in a year or two, you may want to
> >> check whether these additions pass your necessary benchmarking).
> >
> > Ok, I see that point. If I am going to use the PLT Web Server then it
> > makes sense to investigate those options to make using continuations
> > affordable. The problem I was running into, though, was unaffordable
> > memory usage even in the absence of continuations.
> >
> >    Henk
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fastcgi.scm
Type: application/octet-stream
Size: 6794 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20081210/2f8049ec/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fcgi-cgi.scm
Type: application/octet-stream
Size: 1204 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20081210/2f8049ec/attachment-0001.obj>

Posted on the users mailing list.