4

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.

SJaguar13
  • 927
  • 1
  • 6
  • 12

2 Answers2

4

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.

Michael Graff
  • 6,588
  • 1
  • 23
  • 36
  • +1 In addition, it is possible for FastCGI to be run over the network. So, your web-server and application script server could be on different machines. It can also help with load balancing. – sybreon Jan 19 '10 at 01:16
0

FastCGI is an optimized version of CGI. It matches the interface of CGI, adding distributed computing.

You can run python scripts through CGI (the cgitb modules is helpfull), but it is usually better to use a framework such as mod_python for performance and feature reason. The situation is similar with Ruby and Java.

I am not sure what you are trying to do. You can't just replace Mongrel or Tomcat with FastCGI. They are completely different beasts. You have to rewrite the application to fit the interface to the webserver.

pehrs
  • 8,749
  • 29
  • 46
  • So you're saying FastCGI makes CGI faster? – Chopper3 Jan 18 '10 at 18:43
  • 1
    More or less, yes. It is not compatible with CGI, though, because the application must implement the FastCGI protocol, which is different than the CGI protocol. FastCGI keeps the script running to accept more than one request, while CGI is a one-request-per-run thing. So, while it makes it faster, it is not the same thing. – Michael Graff Jan 18 '10 at 19:50