mod_snake_cgi is a PyMod which accelerates and caches CGIs written in Python. In addition, for added functionality, these Python CGIs loaded into mod_snake_cgi have access to the mod_snake module and its routines such as logging.
To use mod_snake_cgi, it must be first loaded into the server. To do this, the following line can be placed in httpd.conf:
SnakeModule mod_snake_cgi.SnakeCGI |
In order to notify mod_snake_cgi that it needs to process a given file type, a handler needs to be associated with certain files. This is commonly done in the main configuration as:
Alias /pycgi/ ``/home/httpd/apache/pycgi/'' <Directory ``/home/httpd/apache/pycgi''> SetHandler snakecgi AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> |
When requests for URI's in the form of: http://your.host.com/pycgi/foo.py are made, they will be run via mod_snake_cgi. The CGIs can be placed in /home/httpd/apache/pycgi.
The directive SnakeCGILogFile will send error information to an alternative file. If this directive is not specified, any output errors or tracebacks will be sent to the ErrorLog.
mod_snake_cgi is a very simple PyMod. When an incoming request is made, the following actions are performed.
The handler is checked against 'snakecgi'. If the handler is otherwise, mod_snake_cgi returnes DECLINE.
mod_snake_cgi checks its internal cache to see if the CGI has been loaded already.
If the CGI is not loaded, it is loaded from the disk and byte-compiled.
If the CGI has been loaded before, the modification time of the on-disk version is checked and reloaded if necessary.
The compiled code runs in its entirety.
Potential future enhancements could include any one of the following:
Handlers for .pyc or .so Python modules which act as CGIs.
Seperate logging facilities within each virtual server.