Faster Web Applications with SCGI
Once you're comfortable writing programs using SCGI, you may want to try adapting existing applications to use it. Some well-known Web applications, such as MoinMoin (a wiki) and Trac (a wiki-based collaborative development environment), are implemented as Python modules. Both of these examples come with CGI scripts in Python that can be called from Apache. The CGI scripts are very short; they really don't do anything except import the application's modules and invoke a function on them.
If you find an application like that, all you really need to do to make it work with SCGI is take that little bit of Python code and move it into a produce() method, as in the examples you've seen here. If you have SCGI 1.12 or newer, you also might want to take a look at an alternative SCGIHandler method, produce_cgilike().
That's about all we have room for. If you wonder about how the CGI parameters work, try looking at the CGI standard, which calls them “request meta-variables” (see Resources).
Finally, a word of warning. You'll notice that the last example program dies horribly if you fail to pass the expected arguments. The SCGI server replaces the failing processes, so in this case, there's no real problem. But, this should remind you how careful you need to be when writing Web applications. Never trust the input you receive from outside! If a program can be crashed, someone can probably subvert it or take it out of action. People all over the world do that sort of thing for fun or profit, so take the risk seriously.
SCGI Downloads: quixote.python.ca/releases
SCGI Home Page: www.mems-exchange.org/software/scgi
CGI Standard: ftp.rfc-editor.org/in-notes/rfc3875.txt
More on SCGI with Python and Apache2: thaiopensource.org/development/suriyan/wiki/UsingScgi
Perl Interface: search.cpan.org/~vipercode/SCGI/lib/SCGI.pm
Lisp Interface: randallsquared.com/download/scgi
Jeroen Vermeulen works for the Open Source Department of the Thai Software Industry Promotion Agency. He's currently working on Suriyan, a server system for those who don't have time for server systems.
- Linux Journal December 2016
- Stepping into Science
- CORSAIR's Carbide Air 740
- A Better Raspberry Pi Streaming Solution
- More on Using the Bash Complete Command
- Tech Tip: Really Simple HTTP Server with Python
- Tyson Foods Honored as SUSE Customer of the Year
- Radio Free Linux
- The Tiny Internet Project, Part II
- Returning Values from Bash Functions