Stateful Conversations with Browsers, Part One
By Randal L. Schwartz
One of the interesting challenges in a connectionless protocol like the Web is maintaining a "session" or "state" information to allow multiple interactions as part of a larger "conversation".
In past columns, I've discussed doing this with external files, with mangled URLs, and with hidden information in forms. While these are good solutions, they all require each new CGI invocation to somehow come up to speed about which conversation this particular transaction is a part.
In this column, I'll use a different tactic: Instead of trying to "leap" the information from one program to another, I'll keep a process alive during an entire conversation, letting it die when the conversation is over. The information can stay in the dataspace of that process, and all we have to do is somehow keep reconnecting to it.
This may sound complicated, but it's actually very simple using the HTTP::Daemon module in the LWP library. I first used this module last year to create a Web proxy server. Here, we'll launch a mini Web-server from a CGI script. The mini Web-server will hold the state of the conversation, and the browser will talk to it instead of the main server.
Each ongoing conversation requires a separate process, so this method only works nicely with a small number of simultaneous "conversations." Next month, in part two of this column, I'll show how to do it with just one additional process.<>