(Prev Next) Part of UserLand's MIDAS Website. Wednesday, August 27, 1997.

FCGI Gateway

With more web servers coming on the market there's an opportunity to streamline the connection to Frontier.

By Dave Winer, dwiner@well.com

This code is for C implementors, primarily people who are working on web server software.


Download ftp://ftp.scripting.com/userland/fcgiGateway.sit.hqx.

Also be sure you have the latest version of Frontier.

What you get

The FCGI Gateway folder contains a Think C 7.0 project and its source files. It builds on UserLand's IAC Toolkit, which is also included, but it's mostly sample code that shows how to connect to Frontier using the Open Scripting Architecture APIs. The real stuff is in fcgi.c.

Look in main.c, routine callCGI. It probably looks like the dispatcher that you'll find in your server software. If the request ends with ".fcgi", route thru a copy of this routine, or something that does something like it.

callCGI calls frontRunCGI, in fcgi.c, which calls callcompiledscript, which sends an 'sdoc' event to a compiled script embedded in the resource fork of your app. You'll probably want to include fcgi.c in your app as-is, or by replacing the calls to IACxxx routines with your own friendly interfaces on the Apple Event routines. They're used to prepare the events to send to Frontier, we use the OSA transport, which builds on the Component Manager, which is much faster than the Apple Event Manager.

To install the embedded script in your app, first launch Frontier then double-click on suites.fcgi. Open fcgi.embeddedScript. Look at it. Open installEmbeddedScript. Edit the first line, change:

local (rezfile = "Macintosh HD:Programming:fcgi:fcgi.[pi].rsrc")

to point to the file on your system. Click on Run. A dialog should pop up saying "true" meaning that the resource was successfully copied into the resource file.

To test it out, try:


You should get back a list of the parameters. All should look OK.

To really stress it, try installing UserLand BBS or the Guestbook CGI which are available thru www.scripting.com at:

My Comments

The sample program, fcgi app, makes 100 fcgi calls and then quits. It reports the results in the little window that it opens. Before installing the software in your server, please try out the sample app. Be sure Frontier is running.

It's not quite as fast as I hoped it would be, but the speed of the connection is very fast. You can see this by replacing the call to callCGI with callTestScript.

I think after this connection is working it would be a good idea to revisit the work that system.verbs.traps.['WWW[omega]'].sdoc is doing, to see if it can't be optimized or streamlined or parts coded in C.

Maybe we can do more work on this side of the fence? That's an interesting idea.

This page was last built with Frontier on a Macintosh on Wednesday, August 27, 1997 at 7:36:34 PM. Thanks for checking it out! Dave