Laughing at the News
By Randal L. Schwartz
In a recent newsgroup thread I was following, someone posted a question about creating a CGI-to-NNTP gateway. This would permit in-house staff to access an NNTP server in a limited fashion via the Web, without having to use a news client. I initially balked at the idea because every CGI hit is a separate process, requiring the script to reestablish a connection to the NNTP server. And from what I've seen, NNTP servers tend to be mighty slow on that initial handshake.
But I thought about it for awhile, and realized that if the first hit could start a Web "miniserver," then that single miniserver could keep the connection alive at very little overhead cost.
We can use the HTTP:Daemon module I wrote about in December 2000 to maintain an NNTP connection. This same technique could also be used to keep a connection alive to a database, or perhaps even a shell session. (Hmm, there's an idea for another program.)
To demonstrate how this works, I've written a script that browses the rec.humor.funny (RHF) newsgroup, and displays the joke-of-the-day posted by the RHF people. Because anyone can invoke this CGI program from anywhere in the world, but only people at my ISP can use my news server, I must ensure that I'm complying with any reuse agreements for content hosted on the news server. Caveat Executor.
Configurations and Preparations
The script in
|