|Did you know ...||Search Documentation:|
|Pack fcgi -- README|
pl-fcgi is suited for CGI applications written in Prolog as it can provide substantial performance gains. Standard Prolog CGI applications must load the Prolog interpreter and parse the CGI script upon each invocation; with pl-fcgi the interpreter is loaded once and the script is parsed once.
A typical pl-fcgi script contains the following sections:
forall(fcgi_accept, ( % code to process request ... ) ).
pl-fcgi applications, like standard CGI applications use the standard POSIX streams (stdin, stdout, stderr) to communicate with the HTTP server.
Prolog code written using pl-fcgi predicates will work both as standalone CGI scripts and with FastCGI servers. The pl-fcgi library automatically detects whether the script is running under a FastCGI server or as a standalone CGI script.
The following example illustrates how a single invocation of a Prolog interpreter is used to service multiple client requests.
flag(count, N, N+1),
format('Content-type: text/html\n\n', ),
format('<title>fcgi example</title>\n', ),
format('<h1>fcgi example</h1>\n', ),
format('Request number: ~w, Process ID: ~w\n', [N, PID]),
forall(fcgi_param(Name, Value), format('<p>~w=~w</p>\n', [Name, Value])),