Monkey: Palm Protocol / Application Server

In some previous post about Monkey HTTP Daemon project, i have been describing some parts of the new architecture and goals that we are trying to accomplish. Now we have a faster asynchronous web server, very lightweight and with a good designed API to extend the features through plugins.

I have received some questions about dynamic content generation support, specifically questions like "what about CGI and PHP support ?", so now is time to describe more in detail how we are handle this through our Palm Protocol.

Palm Protocol, aims to provide a simple CGI applications server which work over TCP. Is pretty much similar to FastCGI or SimpleCGI, but still more simple ūüôā , basically is a TCP server listening in different ports to serve different dynamic content in a pre-forked model. To explain it better take a look to the following diagram:

Server Side

Palm server create specific handlers per configuration, for example, it can be configured to serve PHP and Python scripts, each handler contains information about how many child process will be available, the executable interpreter and optional arguments for it, for example, in order to define a handler for PHP we could add this entry in palm.conf:

Port = 2010
Exec = /usr/bin/php-cgi
Arguments = -f
Childs = 5

That entry specify that the handler will be listening in TCP port 2010, it will create 5 child process and each request will be server by the php-cgi program, adding the -f argument before the script to be called.

Each handler created is called a 'Palm', you can configure as many Palms as you want.

Client Side

In the client side, the Palm Plugin for Monkey HTTP Daemon will be listening for specific file extension on each HTTP request, so it can be configured to handle files with .php extension and connect to the right Palm. Here's a simple configuration line for PHP in the client side, this configuration take place in the plugins/palm/palm.conf file:

Palm   php   application/x-httpd-php     2010

Each row in the configuration file represents a Palm entry, the fields required are: protocol, file extension, mime type, palm server address and palm server port. This configuration must match the Palm server configuration. So every time that a PHP file is requested, the Palm client will connect to the Palm server to the specific port, send the request and wait for a response.

Protocol details

The protocol as mentioned before, is very basic, is composed by the following:

absolute_script_path + CRLF    (mandatory)
cgi_header = value + CRLF      (optional)
CRLFCRLF                                (mandatory)

a text example could be:


The first mandatory row indicates the absolute script path to be interpreted or executed, the second optional row represent the CGI/1.1 headers used by the interpreters, you can add N cgi headers as required, and the final mandatory row indicates the end of the request.

If any error occurred in the server side, the Palm server must return a formatted plain text or HTML error to the client side, Palm Protocol does not handle error codes.