What are WSGI and CGI in plain English?

Every time I read WSGI or CGI, I compress. I tried reading it before, but nothing got stuck.

What is it really in plain English?

Does it just send requests to the terminal and redirect the output?

+72
python wsgi cgi
Feb 08 2018-11-11T00:
source share
4 answers

WSGI starts the Python interpreter when the web server starts, either as part of the web server process (built-in mode) or as a separate process (daemon mode) and loads the script into it. Each request calls a specific function in the called script, and the request environment is passed as arguments to the function.

CGI runs the script as a separate process for each request and uses the environment variables stdin and stdout to "communicate" with it.

+41
Feb 08 2018-11-11T00:
source share

From a completely opposite point of view, Blankman, here is my "Entry Page" for the web services gateway interface:

PART ONE: WEB SERVERS

Web servers serve responses. They sit patiently waiting, and then suddenly without any warning:

  • the client process sends a request. The client process can be a web server, bot, mobile application. It is just a "customer"
  • web server receives this request
  • intentional mumble various things happen (see below)
  • The web server sends something to the client
  • web server sits again

Web servers (at least the best) are very VERY good at this. They scale up and down depending on demand, they reliably conduct conversations with the brightest customers on truly collapsed networks, and we never have to worry about it. They just continue to serve.

This is my point: web servers are just like that: servers. They donโ€™t know anything about content, nothing about users, nothing but how to wait a lot and respond reliably.

Your choice of web server should reflect your delivery preference, not your software. Your web server should be responsible for the service, not for the processing or logical material.

PART TWO: (PYTHON) SOFTWARE

The software is not sitting. Software exists only at runtime. The software is not very convenient when it comes to unexpected changes in its environment (files are not where they are expected, renamed parameters, etc.). Although optimization should be the main principle of your design (of course), the software itself is not optimized. Developers optimize. The software is running. The software does everything in the "Intentional Mumble" section above. It could be anything.

Your choice or software design should reflect your application, your choice of functionality, and not your choice of web server.

Here, the traditional "language compilation" method for web servers becomes painful. You embed code in your application to cope with the physical server environment, or at least have to choose the appropriate wrapper library to include at runtime to create the illusion of uniformity on all web servers.

SO WHAT IS WSGI?

So finally, what is WSGI? WSGI is a set of rules written in two halves. They are written in such a way that they can be integrated into any environment that welcomes integration.

The first part, written for the web server, says: โ€œWell, if you want to deal with the WSGI application, this is what the software will look like at boot. Here is what you need to make available for the application, and here is the interface (layout) "which you can expect from every application. Moreover, if something goes wrong, thatโ€™s how the application will look and how you can expect it to behave."

The second part, written for the Python application software, reads: โ€œWell, if you want to deal with the WSGI server, this is how the server will think when it contacts you. Here is what you need to make available to the server, and here the interface (layout) that you can expect from each server.Moreover, if something goes wrong, this is how you should behave, and this is what you should tell the server.

So, you have it - the servers will be servers, and the software will be software, and here they can do fine without resorting to any additional advantages with respect to the features of the other. This is the WSGI.

mod_wsgi, on the other hand, is a plug-in for Apache that allows it to talk to WSGI-compatible software, in other words, mod_wsgi is the implementation - in Apache - of the rules of the first part of the above rule.

Regarding CGI .... ask someone else :-)

+165
Feb 25 2018-11-17T00:
source share

If you are unclear on all terms in this space and may come across this, its confusing abbreviation, there is also a good reference reader in the form of the official Python HOWTO, which discusses CGI and FastCGI vs. WSGI, etc.: http://docs.python.org/howto/webservers.html . I wish I read it first.

+11
Mar 29 '12 at 20:10
source share

Both CGI and WSGI define standard interfaces that programs can use to process web requests. The CGI interface is at a lower level than the WSGI, and includes a server that sets environment variables containing data from the HTTP request, while the program returns something formatted much like the voice response of the HTTP server.

WSGI, on the other hand, is a Python-specific interface with a higher level that allows programmers to write applications that are aggregated to the server and that can be wrapped in other WSGI (middleware) applications.

+10
Feb 08 '11 at 4:50
source share



All Articles