Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FastCGI, SCGI,

Tags:

c

php

cgi

fastcgi

I'm writing a web server in C, and I need to figure out a way to use CGI to execute dynamic content server-side.

I'm looking at the FastCGI protocol and it looks annoying. It reminds me of the bit twiddling I had to do in a class when I was converting ASCII to UTF-8 and back (that seemed useless then, but maybe it wasn't...)

I found a great library written in PHP where I could just start up php-cgi -b localhost:8888 and start communicating with it. Obviously, I'd like that in C.

I'd appreciate it if someone could find a library (for FastCGI clients!). If not, then I'm fine with contributing to the open source community by writing one.

Also, how exactly do I use SCGI? There's barely any documentation on it (that I can find, anyway). What socket do I connect to? Where do I send the requests?


Also, php-cgi is only for PHP, so how do things work for Perl, Python, etc?

Thanks again.

like image 279
Preetam Jinka Avatar asked Apr 19 '11 03:04

Preetam Jinka


People also ask

What is the use of FastCGI?

Basically, FastCGI is a program that manages multiple CGI requests within a single process, saving many program instructions for each request. Without FastCGI, each instance of a user requesting a service causes the Web server to open a new process that gets control, performs the service, and then is closed.

What is the difference between CGI and FastCGI?

What makes a difference from CGI is that with FastCGI the running process of the application lasts longer and it is not immediately terminated. After the application finishes processing and returns the output data, the process is not terminated and is being used for processing further requests.

Is FastCGI fast?

FastCGI is a fast, open, and secure Web server interface that solves the performance problems inherent in CGI, without introducing the overhead and complexity of proprietary APIs (Application Programming Interfaces).

What is FastCGI Django?

Essentially, FastCGI is an efficient way of letting an external application serve pages to a Web server. The Web server delegates the incoming Web requests (via a socket) to FastCGI, which executes the code and passes the response back to the Web server, which, in turn, passes it back to the client's Web browser.


1 Answers

mario said (in the question comments):

  • There are a few libraries mentioned on the FastCGI homepage. http://fastcgi.com/drupal/node/5. The development kit should include the server.
  • The client implementation is included there for, too. http://fastcgi.com/devkit/doc/fcgi-devel-kit.htm
  • SCGI http://python.ca/scgi/protocol.txt is extremely simple to implement even without reference code.
  • You need an SCGI client that runs as deamon, and that accepts socket connections on an agreed port (4000 or 5000 seem common).
  • SCGI is no different than FastCGI. Each language would require its own daemon, you can run multiple. And accepting CGI requests is pretty much what they do. The only difference is the socket and the header format instead of a CGI stdin pipe and env variables.

To this I'd like to add: CGI (which is exactly what the question asks for) is different from FCGI and SCGI in their working models. It's quite easy to mistake one for others. Luckily, it seems like Preetam asked for FCGI and SCGI.

like image 140
Nam Nguyen Avatar answered Sep 25 '22 02:09

Nam Nguyen