Forum Moderators: coopster & phranque

Message Too Old, No Replies

CGI script, forking deamon, sleep

Problem with sleep in CGI script

         

rajatgarg

5:48 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Hi,

I am running a CGI script that executes external script. This external script forks and exits itself to become deamon and writes its responses to log file. This is necessary to take care of timout issues.

Now, I read from the log file in a do-while loop and check for end of marker or just print "." , so that browser doesnt timeout, even if the execution of script takes 30 minutes.

I tried to use sleep between do-while loop, so tha status is checked every minute. Problem is that when I insert sleep, somehow CGI waits at thes tep, where I execute
external script, and does not go to do-while loop. (NOTE: Sleep is in do-while loop)

Code is below:

`./install_rootfs.pl $ROOT_FS $REPOSITORY $TARGET $in{toolchain}`;

# if sleep introduced below, nothing gets printed after install-rootfs command

print "<li> RG ";

my $LOGFILE = "log_to";

my $LTP_compilation_over = 0;
do {
eval {
open (LOG, "$LOGFILE") ¦¦ die ("Cannot open file");
my @log = <LOG>;
close (LOG);
if ($log[$#log] =~m/Status=100/) {
print "Compilation over";
$LTP_compilation_over = 1;
}
};
# problem with sleep
sleep 10;
} while ($LTP_compilation_over!= 1);

Any other ideas.
Kindly help. I have spent 2 days trying to find logical solution to this

~rajat garg

moltar

7:46 pm on Aug 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you have a problem with the buffer. You need to look into nph scripts and print new line character at the end of each string.

You mentioned that you just print a '.' character to keep the browser awake, try printing ".\n". New line will flash the buffer and output. That would work on the command line, but I don't think it will work in the browser though. You need to use nph for that.

this is all imo, i haven't tested it.

jollymcfats

11:06 pm on Aug 22, 2004 (gmt 0)

10+ Year Member



You can force flushing STDOUT on every print by setting $¦ to 1. Check
perldoc perlvar
for $OUTPUT_AUTOFLUSH.