Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Server Pushing from Perl to the webpage

Status
Not open for further replies.

tcollins

Programmer
Sep 12, 2000
34
0
0
US
I need to display something like a status bar when pulling information from a data base that takes some time to perform. This is easily accomplished with a table code like:
print &quot;<table width = 100% border = \&quot;1\&quot;><hr><td width = &quot; . $size . &quot;%>A</td><td>A</td></hr></table>&quot;;
but how do I get this pushed in real time? At one time Netscape 1.1 had a server-push technology that worked only with Netscape. What is today's recommended method for pushing a counter or status bar out to a webpage in real time from an application such as Perl?
 
CGI.pm supports server push, but I believe its not being pushed (forgive the pun). Check out Lincoln Steins' pages

You could have a frame that refreshes each second, and reads the status. Other than that you could get/write a Java applet that can read real time status from your process. That's if the real time status is that important.

I've seen pages that refresh to the results

<html><head><title>Blah Blah</title><meta http-equiv=&quot;refresh&quot; content=&quot;3;URL=http://mysite.com/cgi-bin/myscript.pl?key=whatever&quot;></head><body>We're reading the database, and you'll be redirected in 3 seconds</body></html>

myscript.pl reads key and picks up the results - can be a head wrecker for housekeeping

--Paul
 
It appears to use the Netscape version of server push:
&quot; WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY
Wasn't this a Netscape only thing a few years ago? Is there a clean way to do dynmic updating of a web page that is not browser specific?
A 'refresh' is undesireable it it will relaunch the queries, I think, but I could be wrong.
Writing the Perl status out to a file for some other process to pick up on a refresh is a bit ackward.
Maybe I need to take a look at the Java applet suggestion? Any thoughts on how to get a real time counter update from Perl while it is running into a Java applet that is on the page? Is there a interprocess communication that I can do?

Thank you.
 
idea-o-matic(ideas) more or less pseudo code.

get $size the eay you do
while ($size=1) {
push(@_, $size);
for each $_ (@_) {
print "<table width = 100% border = \"1\"><hr><td width = " . pop(@_). "%>A</td><td>A</td></hr></table>";
}
 
Without reloading the page this is not practically doable. Why? Because the client (browser) has no idea how long the server will take to complete the action.

This essentially renders any sort of 'progress' bar meaningless.

I have found sticking an animated gif of a 'barber pole' (moving stripes that loop) makes people happy.

If your really needing to alert the person when its done you can fork the db and then reload the page every few seconds checking for the final results status but I think thats more trouble then its worth..
 
Correct, what I don't want to end up doing to having a page refresh itself concering the progress. The length of time to collect the data that Perl is retrieiving is very dependant on a lot of things. That is why to have a dynamically updated progress bar is desired so that we can see how much data has been retrieved and how much more we have to go, with an approximate estimated to completion time. I'm looking for a clean way to do this. A barber's pole is one method, but doesn't tell me if the process is actually doing something or how much longer it will take. It only tells me that my browser is looping through a static image sequence. Or maybe I should just do the whole thing in a Java Applet?

I would be ideal to have the abilty to re-write previously written data. If I do a simple progress bar and loop it, I get about 10,000 of these bars, one under another, progressively getting larger and larger. I don't want 10,000 of them. I only want one, but overwritten with new data periodically. Netscape's very old and non-cross-platform-friendly version did this. But since it is no longer really supported.....
 
I don't think you can push the image - that's just not how the web works. How about putting the progress bar (only) in an iframe which you can then refresh every n seconds? Users of ancient browsers won't see it, but otherwise it should be a good solution.

Failing that, Java might be the way to go - returns some likely leads.

-- Chris Hunt
 
Incidentally, I think you'll need (at least) three seperate scripts to do this...

1) To start the process running and display a page including the <iframe> or applet telling the user to wait.

2) The actual script to do the long-winded processing that you're talking about. It'll need to regularly write it's current status somewhere that other scripts can read (like a file) - and remember, because it's the web, there may be many instances of it running at once! Final results need to be wrtten somewhere too.

3) A script to read the status information produced by (2) and return it. If you go with the <iframe> method, this script would either return a part-complete status bar page with an http header saying "refresh me in n seconds", or a "task complete" page (that doesn't refresh) with a link to the final results.

It's all going to be pretty fiddly - are you sure it's worth it?

-- Chris Hunt
 
Here is a very short CGI script that will do exactly what you need (works well under any Netscape version)

[save the following in e.g. mydynamicscript.cgi - it will display a different random number every second]
Code:
#!/usr/bin/perl -w
use CGI;

print "Content-type: text/html\n\n";
print "<html>";
print "<meta http-equiv=refresh content=\"1; url=mydynamicscript.cgi\">\n";
print rand();
print "</html>\n";
 
another possible solution you might look into is flash.
I know that flash can be used with with server scripts and databases so that reloading the page no longer becomes nessasary.

...just an idea
 
A solution I worked out for the same type issue. This one relies on frames and a tiny bit of javascript.

In general, you send your user to a page that is composed of two frames. The first frame has its size set to zero and make s a cgi call to run the long running process. That 'invisible' first frame also has an 'onload' javascript event that redirects the browser to the yet to be generated results set. The second frame which occuppies the entire browser, simply displays an animated gif or javascript counter. The second frame sits and shows the user the counter until it is high-jacked by the 'onload' event in the first frame that does the redirect to the results set.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
goBoating, this has the look of FAQ about it ;-)
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top