Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Can a CGI web-page update live?

by C_T (Scribe)
on Oct 06, 2004 at 15:50 UTC ( [id://397043]=perlquestion: print w/replies, xml ) Need Help??

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

This may seem like a silly question, but some people have claimed it can be done. If anyone knows how to do it, you guys will, so here goes...

Right now I have a CGI page which does the following:

1) Click here to do many things 2) Many things are done 3) Display the results of the many things that were done
What I'd like is:
1) Click here to do many things 2) Doing thing one... 3) Doing thing two... 4) Doing thing three... etc.
In other words, I'd like the user to have real-time feedback on what's going on behind the scenes in Perl.

If possible, I'd like to have this display happen without updating the webpage, but that seems not possible with what I currently know about CGI and HTML.

I'd rather avoid writing an applet or java application to do the user feedback as the tasks are performed. Perhaps the only way is to have something refresh the page automatically every few seconds?

If anyone has any ideas, please let me know. I'm open to all suggestions.

Thanks!

CT

Charles Thomas
Madison, WI

Replies are listed 'Best First'.
Re: Can a CGI web-page update live?
by Plankton (Vicar) on Oct 06, 2004 at 15:58 UTC
    You want to do this ...
    $|=1;
    ... in your script. You can search for $| or buffering CGI and find a lot of other nodes about this. You can also take a look at one my nodes Jumble solver CGI that demostrates $|=1
      This is fantastic and does exactly what I want! The only problem is that the browser times out before the script gets everything done.

      Is there a way to tell the browser not to time out?

      CT

      Charles Thomas
      Madison, WI
        You need to keep writting to the browser. Here's a snippet from Jumble solver CGI that does that.
        sub spelled { my $word = shift; my $out=`$speller $word`; chomp($out); if ( ($loopCount++ % 10) == 0 ) { print "." if ($charCount % 4) == 0; print "o" if ($charCount % 4) == 1; print "O" if ($charCount % 4) == 2; print "o" if ($charCount % 4) == 3; $charCount++; print "<BR>\n" if ($charCount % 29 ) == 0; } if ( length($out) > 0 ) { print "[$out]<BR>\n"; } }
        the sub spelled gets called from the permute sub (which is not really the most effiecent way to solve jumbles but is useful for demostrating how to keep the browser from timing out) ... well the sub spelled writes to the browser via the calls to print ...
        print "." if ($charCount % 4) == 0; print "o" if ($charCount % 4) == 1; print "O" if ($charCount % 4) == 2; print "o" if ($charCount % 4) == 3;
        I hope that helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-28 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found