Solved! Telling a browser to keep a connection alive
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Sun Jan 8 03:03:19 UTC 2006
Hi all,
I got a lot of feedback on this problem when I posted a little while
ago so I wanted to post an update...
I tried Fraser's Non-Parsed Headers trick and that gave me /more/
time but in the end, the connection still died if the server took too
long to respond. It was a great piece of info though!! I suspect I'll be
trying that trick elsewhere later.
I tried a different web server (three in all, xs_httpd, apache2 and,
the one that I've used for a while, Boa) and tried playing with their
KeepAlive and Timeout settings but in the end, it could still die...
What finally worked is:
I had the main script call a secondary script that printed it's
output to a file. The main program called this file using '& |' to
disconnect and return. To be sure I didn't have a run-away script, I
would watch for a specific temporary file to appear. If it took more
than ten seconds than I knew the secondary script failed and I die. If
it did show up though then I knew it launched okay and and I read it's
contents and printed it to the screen.
When the secondary script starts it adds and html REFRESH to the top
of the page. This refresh calls the main script every period of time
passing an extra cgi variable to tell it that it's just refreshing the
screen. Before doing this though it checks the 'mtime' of the temp file
to make sure it's still being updated. If the file hasn't been updated
recently (X seconds) it considers the secondary script to have died,
kills the temp file and prints an error.
So long as the temp file is still being updated though the main
script will read the temp file and print it's contents to the screen.
The last thing the secondary file does when it is finished is to re-read
the temp file, delete the REFRESH line and re-save the file. This way
the last time the main script loads the contents of the temp file it
stops refreshing the screen.
The secondary script will, after waiting 2 seconds longer then the
REFRESH time, delete the temp file to clean up.
Voilà! A connection between the client and the server that will not
die. More over, the user can even close his or her browser on a big job
and periodically reload the page to see how the job is doing (ie: a
backup job that could take hours on very large systems).
I am sure it could be done more elegantly but for me, it works. :p
Madison
PS - Thanks to Marc (and Cameron here at home) for suggesting the "pull
from client method".
PPS - Thanks to Tom for the article on users and wait times.
PPPS - Thanks to everyone who replied!!
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Madison Kelly (Digimer)
TLE-BU; The Linux Experience, Back Up
Main Project Page: http://tle-bu.org
Community Forum: http://forum.tle-bu.org
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list