views:

111

answers:

2

This is more to understand the request-response mechanism in web apps. A client sends a request (GET / POST) to a web app. The web app has an application server running which serves as the container for the application specific programs. I don't understand the part when the app server starts a FastCGI / CGI process. What is the significance of CGI? Aren't the servers designed to handle the complete request handling mechanism? What part of the request handling relies on CGI?

A: 

The communication between the client (tipically a browser) and the Web server is over http. When the Web server receives a Request, it analyzes what the request ask for, and return the appropiate output. The request can be to a file stored on disk, then the server just returns the content of the file. If the request identifies a program (your CGI) it will execute it and return the output of your programm to the Client.

Dani Cricco
Thanks Dani. Let me be a little more specific here. Suppose I am serving a Rails app. The client requests for a resource, which is specific piece of my program (typically a message to a controller object). Where does CGI fit in here? Shouldn't the app server (like mongrel) be able to run the program and return the response to the client?
Vaibhav Gumashta
If you are using mongrel then you wouldn't be using CGI.
David Dorward
Exactly!. CGI is a term that refers to the execution of a "console application" by the Web Server. CGI is the communication between the Web Server and a console application.With mongreal your application will be running "inside" the Web Server.
Dani Cricco
A: 

I asked a similar (although it's more close to implementation then concepts) question here: http://stackoverflow.com/questions/2157223/http-request-dispatch-from-web-server-to-a-cgi-fastcgi-process

However, here's what I've been able to learn on the way: CGI is a set of "standards" that define how an HTTP/Web Server should communicate with external programs. Note the word standards! Although not an out and out protocol (like HTTP, TCP etc) but it is pretty close being one as the set of standards are complied to by most of the external programs that generate HTML (Ruby, PHP, Python etc).

You can read more about CGI here: http://hoohoo.ncsa.illinois.edu/cgi/intro.html

and here: http://www.w3.org/CGI/

FastCGI is an improvement on the way CGI processes are handled - put in a super simple way a FastCGI process stays loaded in the memory for a longer time so that it can process multiple requests while it's loaded in the memory. Obviously that works more efficiently since the time & resources lost in loading the basic CGI environment never does happen that frequently in FastCGI processes

A little off the track and Rails specific, but this is an interesting artice: http://izumi.plan99.net/blog/index.php/2007/04/05/saving-memory-in-ruby-on-rails/

Vaibhav Gumashta