Why CGI is a great protocol for today's personal web
# CGI?
Ah yes, the venerable Common Gateway Interface of the 90s. It is a way to let any program on the server, or application in today terms (or a php/perl/whatever script), access the web. The beautiful thing about it, is that no special mechanisms are needed; Input from the web socket to the program is on standard input, and output from the program to the web socket is on standard output.
For each incoming request that arrives at the webserver, it will spawn itself and start a new process to handle the request. When many requests arrive at the same time, many processes are active together, and that can would chock the server, or at least it did 10-20 years ago. Nowadays the servers are much faster, with many more cores and hyperthreading, and the operating systems (linux/*bsd) are much better at spawning processes. Just make sure to use a webserver that uses a small amount of memory while doing it’s thing.
# Why now
The last 10 years or so we have seen an explosion in the number of new languages, scripting languages, esolangs, and whatnot. Each of these can accept input from standard-in and write to standard-out (At least most of them can).
Most of these don’t have a more sophisticated way to access a web socket, but by using the standard input and output pipes, the web is just writeln("hello world!") away!
While reading HN I stumbled on a post by Jake Gold, and a related one by simon willison. They explain the mechanics of CGI and show that it’s possible to serve hugh amount of requests by using it. Actually, this here blog uses the althttpd web server that spawns itself for every request, just like CGI. I also use fossil-scm which also uses CGI to connect to the web. I don’t know if it will survive the “HN hug of death”, but I don’t plan for it either. How often does that happen anyway?! And if it does, who cares? Just get the webserver up and running again and thats it.. (and if it’s intersting enough, someone will cache it on archive.org)
# Fun Fun Fun
So, let’s make the web fun again, and use Piet, Fish, Befunge, janet or whatever to make small snippets for the web, or even a whole site. Just remember to put everything inside chroot jail, so your webserver doesn’t melt down if something bad happens..