http://qs321.pair.com?node_id=84105


in reply to Re: Re: Connection: Keep-Alive and Perl
in thread Connection: Keep-Alive and Perl

Keep-Alive in my understanding is really for keeping the server listening to the connection for a time after the initial transaction (So it doesn't have to spawn a new server for the next connection. Say if it's downloading a bunch of images from a web page.)

For keeping the browser around a long time I find that you have to keep talking to it. I have a database converter for a client that can take upwards of 30 minutes to run. What I do to keep the connection alive is by disabling buffering and before the long process I output a message like

"Processing please wait...
(This will take approximently 30 minutes. Go get a cup of coffee.)

Then as I process the data, I print a "." or something after every couple of hundred records (like sftp) so they know it is still going (and hopefully they don't get impatient and hit refresh as the process is HUGE and I don't want to start another one for no reason.)

There is probably a lot of ways to accomplish this. If you are forking I would do something similar and have the parent use sleep to time the printing. Keep in mind this solution is a bad idea if you expect a lot of people to be using these programs as your tying up a lot of resources. For my problem it's fine as only one person runs said program once a day.

-Lee

"To be civilized is to deny one's nature."
  • Comment on Re: Re: Re: Connection: Keep-Alive and Perl

Replies are listed 'Best First'.
Re: Re: Re: Re: Connection: Keep-Alive and Perl
by mattr (Curate) on May 30, 2001 at 10:55 UTC
    Thank you dfs and shotgunefx, two great ideas.

    The big problem was browser timeout, which had not solved itself by just printing dots. I do dots a lot, maybe spaces that don't display would be good. For some reason I remember thinking the browser was timing out even with the dots being printed, but obviously the process must have just taken too long.

    I had looked at IO::Tee (output to multiple handles) but I guess the answer is really just a fork as shotgunefx suggested. The Perl program directs the spidering and indexing of many websites into separate databases, so I would fork a child for each site, then have the child return a success code on finishing its work. I suppose this would even run more quickly with many children in parallel but I think I'll keep it serial for now to keep the log file readable.

    Thanks. I guess I was a little *too* lazy a perl programmer.

Re: Re: Re: Re: Connection: Keep-Alive and Perl
by mattr (Curate) on May 31, 2001 at 08:37 UTC
    Thank you both dws and shotgunefx, I posted a longer reply but it didn't get into the system apparently.

    I seem to remember trying periods and the browser timing out anyway, but it was probably just too much time between periods.

    This was for a perl program called by cgi which directs the spidering of a number of sites and indexing of them. I had looked at IO::Tee, but since I only want the browser to display a very short summary with the log file containing more detail, in the end a fork and spaces being printed by the parent seems best. I supposed I could run a number of children in parallel but when I've done this in the past I got two activity logs interleaved in one file, so I'll keep it serial for now.

    I guess I was *too* lazy a perl coder. :)