469,646 Members | 1,596 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

CGI autoflush in Window


I have the following script


#!D:/Perl/bin/Perl.exe -w

use strict;
use CGI ":standard";
$| = 1;

my $MYFILE = "D:\\Apache\\logs\\mgmtwrkstn\\lucky.txt";

if (param("monitor")) {
} else {
if (fork) { # only need to fork for IE
print redirect(-uri => url() . "?monitor=yes",
} else {
sub monitor
my $html = &draw_page();

if (defined $html) {
print header(-refresh=>1, -nph=>1), $html;
} else {
print header(-nph=>1), &goodbye();
sub goodbye
return start_html(-title=>"Goodbye!") . h1("Goodbye!") .
sub get_number
open NUMBER, "<$MYFILE" or return undef;
my $number = @glo;
close NUMBER;

return $number;
sub draw_page
my $number = &get_number();

return (defined $number) ? start_html(-title=>"Your Lucky
Number") . p("Your lucky number is $number.") . end_html() : undef;

sub do_stuff
for my $i (1 .. 10)
open NUMBER2, ">$MYFILE";
print NUMBER2 $i;
close NUMBER2;
sleep 1;

unlink $MYFILE;

================================================== =======

What this script essentially do is that it forks a child process to
write 1 to 10 on some file, while writing it, the parent process will
refresh the page every second to read the content of that file. This
script is orginally from

It works under Unix environment with apache. However, when I run this
script in W2K and apache 1.3.x. It doesn't work. It seems like that
the child process is locking the files its writing to and the parent
process can't go into it(even with autoflush on). Therefore, the
parent process doesn't refresh the page until the child process unlink
("delete") the file. Can anyone help me on this one? I am a newbie on
Perl and CGI and I want to continuosly monitor some background job on
a web page.

Jul 19 '05 #1
0 2581

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gianluca Trombetta | last post: by
6 posts views Thread by David Hayes | last post: by
19 posts views Thread by Darren | last post: by
14 posts views Thread by D. Alvarado | last post: by
26 posts views Thread by yb | last post: by
4 posts views Thread by alexandre.brisebois | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.