Zeus Server Dynamic Document API

Overview

Zeus Server provides a high-performance CGI replacement which allows dynamic documents to be provided to its clients. The dynamic document API utilises a TCP/IP socket interface to allow the document generation code to be implemented on a separate machine to facilitate load-balancing, and also makes no restrictions on the implementation language.

The dynamic document generation code, called sockd here in, runs as an external daemon to the server and listens for the request from the server to generate a page. The server then passes information, similar to the environment setup for a CGI process, to the sockd server, which can then use this information to determine the data for the page to generate. This information is then routed back through the server down to the client. This offers significant performance increases over frequently forking a large CGI script.

Usage

The sockd runs as a daemon process, listening on a defined port number. In order to refer to this server when requesting a page, a request is made to the server for a URL of the form /server/socket/[machineip]:[port]<?arguments>, where [machineip] and [port] are required parameters which are replaced with the IP address of the machine running the sockd server, and the port number it is running on. The <?arguments> sections is an optional parameter which is replaced with any arguments to pass to the sockd along with the request information in a similar vein to how CGI scripts work. If the sockd is running on port 3456 say on the same machine as the server, embedding in a HTML page the code:

<a href="/server/socket/127.0.0.1:3456?mypage_counter">test</a>

Would cause the server to ask the sockd to generate a page upon the client selecting that link, and would pass the argument “mypage_counter” along with the request.

Details

A sockd server is a standard UNIX daemon which listens on a port number for requests from the server, and responds as detailed below. Multiple simultaneous requests may be outstanding at any one time.

Input

ENVIRONMENT\r\n
DATA\r\n

Where:

ENVIRONMENT = (LINE\r\n)+
LINE = environment variable line (eg. HTTP_USER_AGENT=ZeusBrowser)
DATA = data supplied to POST, or arguments supplied to GET

ENVIRONMENT contains all of the fields that are set in the environment of a normal CGI program.

Output

As normal CGI

An example sockd server is supplied with the Zeus Server distribution, in the scripts directory called “sockd”. This is a simple page-counter implemented in Perl which demonstrates how to interact with the Zeus Server Dynamic Document API.