Imagine that you are creating a dynamic website in your chosen programming language.
When a user arrives at your site, they go to http://name-of-your-site.com and this is transferred to your server.
When the request arrives at port 80, it is collected by your HTTP server, which is probably Apache, but could be LightHttpd or any other HTTP server. This will receive a request and decide what to do with it.
Now, imagining that your site is written in python, it will be stored as a bunch of .py files somewhere, and therefore the request should be passed at runtime python with instructions to run the file and to return the output from this file. This is the role of mod_python - receiving requests from the server and transmitting them at runtime. Most mods also process a thread pool - suppose you have twenty requests in one minute, if each of them is passed at runtime python in a simple way, then you will have twenty python threads, all running, working together, and then dying as the process completes, typically Apache modifications will support multiple threads up and down to save them during startup and simply transfer new requests to one of the existing threads, so that when it completes one request, it will receive nother interface. CGI containers perform the same task in different ways, the reason you can choose one over the other will most likely be related to which HTTP server you are using (mod_python is for Apache, for example, something like FastCGI used more with LightHttpd) and for performance reasons. If you use something like FastCGI, then you may need a second level of interface between the CGI container and the programming runtime.
So, the layers you work with look something like this:
HTTP Server-> CGI Layer -> Programming Language Runtime -> your code Apache -> mod_python -> Python Runtime -> index.py LightHttpd -> FastCGI+python_cgi -> Python Runtime -> index.py
Obviously, I used Python as an example here, but you can find equivalent mods and cgi containers for most major languages ββ(and many esoteric ones) and the Http stack that you work with will be generally similar in most cases.
source share