From: divya on
Hi,
I have a website that generates responses to a user's query. The
generation of a result takes a really long time (sometimes over two
minutes). I would like to create a "please wait while we are computing
the results page" like the ones I have come across in
www.travelocity.com and the like. The "wait" page is presented to the
user while results are being computed, after they click the "submit"
button in the query page. Once the results are available, the page
changes over to the result page. How does one go about doing this? I
am using Perl/CGI and a minimal amount of javascript.

I want to set up this "wait" page due to the long time that is
needed to generate results. Is there any other way to keep the user
interested and the webpage from expiring while my system is still
crunching the
numbers? I did try setting the "expires" tag in the HTML header but it
did not work. The browser gave up while the system was still working -
I tried on IE6.

I would really appreciate any comments/advice/directions that may
be provided.

Thanks!
Divya

From: A. Sinan Unur on
"divya" <divyanrao(a)gmail.com> wrote in news:1140917133.904701.80920
@e56g2000cwe.googlegroups.com:

> Hi,
> I have a website that generates responses to a user's query. The
> generation of a result takes a really long time


Time for another classic by Randal Schwartz:

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

http://www.google.com/search?q=long+processes+cgi

Sinan

--
A. Sinan Unur <1usa(a)llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

From: Jamie on
In <1140917133.904701.80920(a)e56g2000cwe.googlegroups.com>,
"divya" <divyanrao(a)gmail.com> mentions:
>Hi,
> I have a website that generates responses to a user's query. The
>generation of a result takes a really long time (sometimes over two
>minutes). I would like to create a "please wait while we are computing
>the results page" like the ones I have come across in
>www.travelocity.com and the like. The "wait" page is presented to the
>user while results are being computed, after they click the "submit"
>button in the query page. Once the results are available, the page
>changes over to the result page. How does one go about doing this? I
>am using Perl/CGI and a minimal amount of javascript.

You'll need to use javascript/HTTP protocol to refresh this.

I suppose these days, you could use AJAX to have the browser "poll" and
then load when the document is done. That'll be a challenge, since
you most likely won't know when the results are to be completed. If you
don't use AJAX, you might need a "Still processing...." type of page
on each browser refresh until it's done.

You can sometimes get creative with CSS and the "display: none" property, this
works if it doesn't take too long. (as in, the server doesn't kill the process)

You just make sure and send NOTHING to the browser until it's all ready.

When user clicks "submit" a bit of javascript swaps class attributes so that
a DIV block is hidden while another previously hidden DIV block is shown.

This has very snappy response time and makes the server level stuff easy, but
it's not a perl solution and I wouldn't count on "lynx" supporting it. Look
for some of those blog sites that use DHTML with it's forms. It's really
slick IF you can use it.

This has nothing to do with perl, check into DHTML. (it's actually pretty
easy..)

> I would really appreciate any comments/advice/directions that may
>be provided.

Most of the challenge will take place browser side, but you should be aware
that the server process will be tied up until the results are done. For this
reason, if it's really long or DHTML won't work.. I'd use a fork() (or better
still a double-fork so that your process is inherited by init and won't be
killed by the web server)

The logic goes something like this:

A. Accept request.

B. Determine temporary file/location for results. (could be a key, etc..)

C. Send browser a Refresh: header and/or use AJAX or whatever javascript
you want to use. (this part is not related to perl at all, except that
you'll need to exchange this key so the browser knows which set of results
to connect to.)

D. fork, then, fork again (so that the web server doesn't kill process)
you'll likely want to flush and then close STDOUT/STDERR just before
this stage otherwise you'll get two copies of the buffer. If you're using
DBI or other resources, try as best you can to avoid connecting until
AFTER the call to fork. (lots of reasons for this, but in general it'll
save you headaches)

E. Do your long-running task.

F. Browser reloads, with the result key/filename or whatever you use
to connect browser to results.

Thats the general idea(s), many variations exist.

Jamie
--
http://www.geniegate.com Custom web programming
guhzo_42(a)lnubb.pbz (rot13) User Management Solutions