Most of the questions involving long running cgi processes asked here, get solved by giving the client an id number, telling them to check back in later, like maybe after an email notification is sent. Then you write their data to a database for them to retrieve later. Maybe there is a way for javascript to send a post when the user leaves your page? Like
. You could set a cookie or id, and have the javascript send you the id number that left page, and you can close up the processes associated with that id.
Can you use plain sockets? Sockets would do it easily, ( well there is alot of details) :-). Or are you stuck going thru a web server?