
On Feb 12, 2007, at 23:27 , Albert Y. C. Lai wrote:
Bjorn Bringert wrote:
pwrapper is not an HTTP server, though the Haddock comment can make you think so. pwrapper allows you to talk *CGI* over a TCP port, but I have no idea why anyone would like to do that.
Here is a scenerio. I want a basic web application: someone makes a request, and my program computes a response.
* For one reason or another, I settle with CGI.
* The program is huge and slow to load. (Let's say it statically links in the whole GHC API and therefore is basically GHC itself. :) ) It would suck to re-load this program at every request.
* Or, the program performs work that requires more file-system privilege than the admin of the web server grants. You know, a good admin sets up a web server and all CGI scripts to run with nobody's privilege.
* Or, nevermind performance or privilege. I am a cheapo, and I use a cheapo hosting provider, which only provides me with 3MB of storage. My program weighs 17MB (recall that it links in the whole GHC :) ).
Here is a solution. The program runs as a daemon and never quits; it can run somewhere with sufficient privilege and storage. It talks CGI over TCP. At the web server, which is super-slow, super- paranoid, and super-cheapo, the CGI script is a lightweight C program that redirects everything over TCP to my daemon.
(Here is a counter-solution. The program still runs as a daemon somewhere, but it talks my own protocol over TCP. The CGI script is a lightweight C program that parses CGI into my own protocol. Besides having to design my own protocol carefully, here is a problem: C is a great language for writing parsers that are incomplete, inconsistent, and insecure. :) )
OK, that sounds reasonable, but I think that there are better solutions for those problems. Besides, it's niche stuff that I don't think belongs in the main CGI package. If anything wants it, it's easy to implement. * If you have slow start-up, you can use FastCGI instead of CGI. There is already a Haskell library for that. * If the program needs additional privileges, you can use an external FastCGI program which is started independently of the server. * If you have cheapo hosting, at least Apache mod_fastcgi allows you to run your FastCGI app on a different machine. Another solution would be mod_rewrite + mod_proxy. But if you have another server where you can run your application, why not put your web server there instead of using cheapo hosting? /Björn