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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System time

Status
Not open for further replies.

xmassey

Programmer
Apr 9, 2007
62
GB
All perl scripts I have written will only print information if the user clicks a button which runs a script. Therefore the only way to refresh the information is to click refresh, or include an annoying META REFRESH tag to refresh the page every few seconds. For example if I was to create a chatroom then to check if users had written new messages, I would have to refresh the page. Basically im asking if theres a way to update a perl page without refreshing (automatic). This is because I want to display a live clock. I have a feeling that there maybe a system time function to do this, or a module. However, if there is I would still be interested to know if you have any ideas because I want to create a chatroom too.

So two questions really:

1: How can I display the live time (counts every second without having to refresh the page).

2: How can I refresh a perl script every second without using refresh.

Thanks alot, you guys are a big big help
 
You can use server push, its the only way to do what you are asking that I know of. Last I checked IE does not support server push (never has I think), but Mozilla and Firefox and maybe other browsers do.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you, I have looked into using the module CGI::push and I have found this script...

#! /usr/bin/perl
use strict;

print "Content-type: text/html\n\n";

use CGI::push qw:)standard);
do_push(-next_page=>\&next_page,
-last_page=>\&last_page,
-delay=>0.5);


sub next_page {
my($q,$counter) = @_;
return undef if $counter >= 10;
return start_html('Test'),
h1('Visible'),"\n",
"This page has been called ", strong($counter)," times",
end_html();
}

sub last_page {
my($q,$counter) = @_;
return start_html('Done'),
h1('Finished'),
strong($counter),' iterations.',
end_html;
}

However as you said it isn't supported in IE, though some strange results are produced :s
 
I don't think you want to print a header with that script:

print "Content-type: text/html\n\n";

the do_push() method should handle the headers required for pushing content to the browser. Or did you do that just to get IE to do something?


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I put the print header print "Content-type: text/html\n\n";
in because I recieved an error 500 the first time, and I assumed that might be because text wasn't ready to be outputted.

The above script is alright, it could be handy. However it prints alot of crap with it, and i've tried removing the crap but it errors (i.e. I tried removing qw:)standard);).

What the script does is every 0.5 seconds it will print a new line until the counter gets to 10, when it prints the final page. I was hoping to print the same thing each 0.5 seconds, and over write everything that was previously printed (i.e. I want the print statement taken from a file to refresh).
 
There *has* to be a refresh of some sorts, otherwise you would have a perl script running indefinitely at the server side (one copy per 'chatter').

It sounds like you should look into some AJAX technologies.

Have a javascript timer on your page which makes an asynchronous XMLHTTPREQUEST to your server side perl script. Your perl script will send XML back to the client, and more javascript will use that XML to redraw parts of your HTML document in the client browser.

Obviously, the perl part is but one part in the solution.
 
Thanks brigmar, I have looked into it, and it seems to be what I need
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top