I would like to use FastCGI with shell scripts. I have found several tutorials about writing CGI scripts in shell, but nothing about FastCGI, and I guess this is not the same thing.
Is it possible, and how?
Thank you
Edit: Ignacio: Thank you but this link is 14 years old and says that this is not current开发者_运维技巧ly supported. Is it still unsupported?
The whole point of FastCGI is to avoid spawning a new process for each incoming connection. By the very nature of the language, a shell script will spawn many processes during its execution, unless you want to restrict yourself greatly. (No cat
, awk
, sed
, grep
, etc, etc). So from the start, if you're going to use shellscript, you may as well use regular CGI instead of FastCGI.
If you're determined anyway, the first big hurdle is that you have to accept()
connections on a listening socket provided by the webserver. As far as I know, there is no UNIX tool that does this. Now, you could write one in some other language, and it could run your shellscript once for each incoming connection. But this is exactly what normal CGI does, and I guarantee it does it better than the custom program you or I would write. So again, stick with normal CGI if you want to use shellscript.
"If you're determined anyway, the first big hurdle is that you have to accept() connections on a listening socket provided by the webserver. As far as I know, (...)" there is one C program doing nearly this: exec_with_piped.c
(it's using pipes, not sockets, but the C code should be easily adapted for your purpose)
Look at "Writing agents in sh: conversing through a pipe"
http://okmij.org/ftp/Communications.html
Kalou
No
I apologize in advance if this is a dumb question but is it conceivable to use a mere shell script (sh or ksh) as a FastCGI program and if so, how?
You can not use a simple shell script as a FastCGI program. Since shell script can not persist across multiple HTTP requests, it can not be used as a FastCGI application. For the program to handle multiple HTTP requests in its own lifetime (i.e. not just handle requests and die, like CGI applications), it needs some means to communicate with the web server to recieve a request, and send the reply back to the server after handling it. This communication is accomplished via FCGI library, which implements the above and it currently supports only a subset of programming languages, like C, Perl, Tcl, Java... In short, it does NOT support shell. Hope that cleared it up a bit. Stanley.
From http://www.fastcgi.com/:
FastCGI is simple because it is actually CGI with only a few extensions.
Also:
Like CGI, FastCGI is also language-independent.
So you can use FastCGI with shell scripts or any other kind of scripts, just like CGI.
Tutorials for CGI are useful to learn FastCGI too, except maybe for the particularities of setting up the web server.
精彩评论