2017-08-27

(sph scgi)

scgi interface. a server that accepts scgi requests and calls a custom procedure to handle them.

see also scgi specification

a program using this interface starts once, listens on a socket, and will be able to process an arbitrary number of requests with a custom set procedure

this differs from cgi scripts which start completely anew for each single request

web servers that support scgi are for example nginx and apache

it is similar to fastcgi, but much less complicated

part of sph-lib

features

automatic socket creation if no socket is passed

supports all types of sockets that are supported by guile

uses the tested (sph server) and (sph thread-pool) libraries to automatically distribute load to multiple available cores

usage example

(scgi-handle-requests
  (lambda (headers client) (display "hello" client)))

nginx example

nginx can be used as a reverse proxy to translate http/https requests to scgi requests passed on a socket to the scgi application

the following is a configuration, for example for "/etc/nginx.conf". the file "scgi_params" should come with nginx and be already set-up

server {
  root /srv/http/test-server;
  location / {
    include scgi_params;
    scgi_pass unix:/tmp/1000/test-application-socket;
  }

scgi_params

this file contains nginx directives to configure the values from the http client request that are passed on to the scgi server application

nginx should have a default scgi_params file, and there may be no need to care much about this file

the following is a customised example (usually the variables are written in uppercase) to show what the contents look like. the only required parameter is "SCGI 1"

scgi_pass_request_headers off;
scgi_param SCGI 1;
scgi_param request_method $request_method;
scgi_param remote_addr $remote_addr;
scgi_param http_cookie $http_cookie;
scgi_param user_agent $http_user_agent;
scgi_param if_modified_since $http_if_modified_since;
scgi_param content_type $http_content_type;
scgi_param request_uri $request_uri;
scgi_param https $https;

library description

http://python.ca/scgi/protocol.txt

import name

(sph scgi)

exports

scgi-default-address

procedure

signature

->

scgi-handle-requests

procedure

signature

handle-request #:socket #:address #:port #:parallelism #:exception-key #:server-listen #:server-socket ->

procedure:{list:header:((string . string) ...) port:client -> any} _ ... -> unspecified

description

optional keyword arguments

#:address string

#:port integer

#:parallelism integer

#:server-listen procedure

#:server-socket procedure

#:socket socket-object

start listening on a socket and call handle-request for each new connection.

the socket protocol-family depends on the address: if it starts with a slash a local unix socket is used, if it contains colons then ip6, otherwise ip4.

if a socket is not given, a local unix socket is created with. default port for tcp sockets is 6500.

server-listen and server-socket can be specified to use alternative server implementations, for example (sph server fibers)

scgi-read-header

procedure

signature

port cont ->

socket procedure:{list:header -> any} -> any

sph-scgi-description

variable

tags: programming guile documentation library scheme sph-lib q1 scgi highlight sph-scgi