FastCGI Plugin is the client side implementation of the FastCGI protocol for interfacing interactive programs with a HTTP Server like Monkey.
In the old fashion mechanism called CGI, to trigger the execution of a script or a binary program, the Server requires to spawn a new process context, this new process is in charge to execute the target file or run it through an interpreter, this is a very expensive procedure at Operating System level. As opposite, FastCGI implements a client/server model where the FastCGI server side, make sure the target resource program is running in an infinite loop and will only by called upon request, when done instead of exit, the program is started again inside the same process context, avoiding process creation waste. This is usually provided by a third party program and for different Script languages exists many FastCGI server implementations.
Using FastCGI is highly recommended when running scripting web programs such as Python, PHP, Perl or any other.
If the plugin have not been built in static mode (check with '$ monkey -b'), you can enable the FastCGI plugin through the following the steps mentioned on Plugins section. The plugin name is monkey-fastcgi.so, so make sure the plugin entry is Load and the absolute path is correct.
The FastCGI plugin takes a global setup on the configuration file conf/plugins/fastcgi/fastcgi.conf that affect all Virtual Hosts. The configuration schema defines the the section [FASTCGI_SERVER] and is used as a reference for all handlers.
FastCGI plugin is a handler, for hence it requires a match rule in the Virtual Host configuration file.
Edit your Virtual Host configuration file (e.g: conf/sites/default) and add a rule to your _HANDLERS section, e.g:
[HANDLERS] Match /.*\.php fastcgi
The match rule defined, specify that the FastCGI plugin will handle all incoming request which it URI ends in .php. Now proceed to configurate the global FastCGI server definition.
The section named FASTCGI_SERVER aims to represent a FastCGI backend server that is listening for incoming FastCGI requests. It supports three main keys: ServerName, ServerAddr and ServerPath.
|ServerName||Local name to represent the FastCGI server.|
|ServerAddr||If the FastCGI Server is listening on a TCP connection, use this key to specify as value the Host IP and target TCP port, e.g: 192.168.0.4:9000.|
|ServerPath||Use this key if the FastCGI Server is listening in a local Unix socket file.|
note: You may use ServerAddr or ServerPath, not both.
The following example aims to provide a setup to make Monkey FastCGI plugin talk to a FastCGI Server that process PHP scripts: php5-fpm.
[FASTCGI_SERVER] ServerName php5-fpm1 ServerPath /var/run/php5-fpm.sock
This example will pass the control of each request to a file ending in .php to the FastCGI server running on the Unix socket /var/run/php5-fpm.sock file.