Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Keeping visitors waiting

by Anonymous Monk
on Jul 25, 2001 at 21:22 UTC ( #99738=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi -

I'm using LWP::Simple to retrieve a number of pages based on user input. Because of the complexity of each page, my "roll a six to start" host, and the complex regexs I'm using, it takes a while. A long while. A very long while.

Now, I'm worried that Joe User will either:

  • Get bored and go away
  • Have his connection time out

So I'm looking to keep the user informed as to how the process is doing.

I've tried using JavaScript to put status messages into text boxes at the top of each page, but the Perl script seems to emit only "chunks" of text and doesn't send text line-by-line, so the status boxes don't change. Could this be related to Cgi-wrap? Or is it because Perl's waiting for the complete page-retrieval subroutine to finish before printing the text?

Thanks ppl!
stamps

Replies are listed 'Best First'.
Re: Keeping visitors waiting
by shotgunefx (Parson) on Jul 25, 2001 at 21:25 UTC
    The first step is to turn off buffering at the top of the script.

    $|++

    If you are worried about the browser closing the connection, you could periodically print out a space character to the browser to keep the connection alive.

    -Lee

    "To be civilized is to deny one's nature."
      Excellent, that's got it.

      Cheers!

      stamps

Re: Keeping visitors waiting
by merlyn (Sage) on Jul 26, 2001 at 03:52 UTC
Re: Keeping visitors waiting
by cLive ;-) (Prior) on Jul 26, 2001 at 00:00 UTC
    I have a script that runs for up to 30-40 seconds. To periodically update the user, I have a null form containing only a textfield. Then, when the script has completed a section, I print something like:
    <SCRIPT LANGUAGE="Javascript"> document.forms[0].elements[0].value = 'Message to user' </SCRIPT>
    So, as the script progresses, the snippet above, repeated for each message, re-populates the text box with a message.

    Used within a frameset (and with $|++) this is quite effective.

    cLive ;-)

Re: Keeping visitors waiting
by toadi (Chaplain) on Jul 25, 2001 at 21:32 UTC
    Maybe time to optimize the regex routines. Use Benchmark to test the speed and try some modification to see if you gain any performance.

    Maybe some regex wizzards here on PM can help you...

    --
    My opinions may have changed,
    but not the fact that I am right

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://99738]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2021-09-23 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?