WebPython: Using FastCGI or WebProxy to Python web server

Ok, I had a long argument with a developer on the net regarding FastCGI and whether or not to use it. Apparently, we didn't manage to convince each other. The developer claims that FastCGI is just an unwanted protocol. The real thing is that he didn't get what it is that I was trying to explain and quite frankly I don't think he even cared to listen other than pitching web proxy as a superior method. Hence this blogpost.

What is WebPython ?
WebPython is Python3 interpreter modified to work in FastCGI as well as CGI mode. You need this as the build uses the interpreter to build its own modules.

REASONS for using WebPython:
(Not the sourceforge project that provides a web framework over wsgi)

1. Simplicity:
FastCGI was designed to replace CGI atleast that is what I believe. If it wasn't and it was meant to be used as a proxy, the author would have named it FastProxy. Also it provides a faster means of access to dynamic pages than conventional CGI pages with the added benefit of simply printing the information that is to be sent to the web browser.

The idea here is to minimize the setup time, time to learn and time to implement. Take any new protocol out on the web, including using web proxy method or WSGI which is being touted as a better solution. What's the problem with those ? Well, the setup time maybe short but the time to learn and implement is far greater than using Python with FastCGI enabled.

The approach is simple, FastCGI is like CGI the output is sent to the STDOUT, the webserver gets the data and sends it to the browser. Here is an example.

#!/opt/PythonInstall/bin/webpython
print("Hello world");

2. Debugging
Remember using STDERR in C programs, well, the same thing works here too. The output of stderr is also sent to the webserver which can then decide to put it in the error log file. You are handed the python stack trace giving you a clear idea of what is happening, now using webproxy or WSGI can't provide such a solution.

3. Maintenance 
Practically anyone can write a CGI program in C. Writing a Python web application using webpython is easier. Ofcourse, you need to know Python3 in order to do that. You simply output it to stdout and you are done. Also, the debugging is very easy as well. Anyone with C/C++ background and some basic knowledge in Python3 and CGI can program in WebPython.

4. Testing Time
All the information sent from the web browser is available as command line arguments and not as environment variables, this is done so as to test out the dynamic webpage easily by just passing arguments to it on a console.












 

Comments

Popular Posts