View Single Post
Old Apr 12th, 2006, 5:35 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Generally, when a CGI script is accessed, the HTTP server will run the script and take the resulting STDOUT from the CGI script and return it to the user in the HTTP response. The Python CGI module allows the script to get parameters and other information from the calling webserver.

The advantage with CGI is that it's relatively simple to setup. All you need is Python on your machine and a webserver capable of performing CGI.

The disadvantages are that CGI scripts are slow, because each time they're run, the Python interpretor has to be started up and parse the scripts. Systems like mod_python and CherryPy keep the Python intepretor and the Python bytecode in memory, so it's considerably faster. Another disadvantage is that CGI scripts are generally more hard work to program. Consider the following CGI script:
import cgi
print "Content-Type: text/html"
print
form = cgi.FieldStorage()
print "Hello %s" % form["name"]
And the equivalent script in CherryPy:
class Root:
    def index(name):
        return "Hello %s" % name
CGI tends to work on a much lower level. It's a no-frills system, and was popular in the early days of the web, but much less so today.
Arevos is offline   Reply With Quote