Java – What specifically does FastCGI do (for Ruby, Java, and Python)

fastcgijavarubyruby-on-rails

If I have a server running Apache, and I install FastCGI, would that let me run Ruby and Python scripts? If Python is already installed on the server, wouldn't I just be able to add .py to the CGI section in the httpd.conf file to have Python scripts working?

For Ruby and Java, does it eliminate the need for Mongrel and Tomcat if Ruby and Java are installed?

Unless I am missing something, it seems like FastCGI only lets you do what you can already do.

Best Answer

FastCGI is a replacement for "standard" CGI scripts.

In old-school CGI, the web server would start up your script, send it a request, wait for a response, then expect your script to terminate.

FastCGI's main feature is that your script doesn't die, but hangs around, waiting for another request. This makes it far more efficient because another process is not created, the probably-interpreted script is not reloaded, etc. This is a major win for Perl, Ruby, and just about every other language.

The downside is that your script must be written to handle this sort of thing. It's not hard.

So, FastCGI is all about reducing the impact of servicing a request.

If you are using Ruby on Rails (not just ruby) then look into Phusion Passenger. It is one awesome server plug-in that makes running Ruby on Rails quite nice.

As for mod_python, you can certainly do that. However, there are trade-offs. For one, a CGI script can run as another user than the main web server. I don't know if mod_python does this. It may be very useful to be able to run as a different user for permission issues, keeping applications separated by running on different users, etc.

So, to answer your question a little differently, if you're willing to use mod_python and Phusion Passenger, then you don't need to use FastCGI. If you must run the scripts in a different process than the server, then you want to use FastCGI if you can, over plain-old-CGI.