The catch is that you always have to return something,
even if that something is "nothing". Some sites feature
a waiting page which refreshes frequently, waiting on output
from something. It might feature a pleasant animated GIF,
and hopefully not something along the lines of WAIT
with the horrific <BLINK> tag.
A quick way of doing this is to create script A which,
when run the first time will fork off script B, and then
refresh to itself with a special parameter. Script B
will write to a certain filename in /tmp, for example,
and script A, when called, will check for this file. When
this file is there, script A prints it, possibly deletes
it, and stops refreshing. The name of the file is encoded
in the special parameter. If, for example, the parameter
"_" was set to "fZdaPXzAQ", then you would be waiting for
the file "/tmp/fZdaPXzAQ.out". The choice of name is
arbitrary.
There are a couple of things you will want to note:
- You might want to write a separate program to clean
out any stale /tmp entries instead of leaving this up to
script A. This way the user can reload the page and still
get output, without you having to process all over again.
- Your script B should not write directly to the /tmp
file, but should create a preliminary version which it
writes to, then renames it at the end to the proper name.
This will prevent script A from jumping the gun and printing
when script B has only written half its output.
| [reply] |
hmm, well the thing is that script A does not need anything at all from script B to execute. Most of the time, script A wont even call script B, but when it does, it does not have to wait for script B to complete, but it does. I think I need to be more clear.. script A simply prints the webpage, and also checks to see if a certain database file is too old. If that file is old, script A calls script B (currently using server(scriptB.cgi);) which downloads a fresh database file from a remote site (this takes a couple minutes cause its a big file). Script A COULD use the old db file until script B is done, but it doesnt because it waits for the server call to complete.
| [reply] |
| [reply] [d/l] |
There was a really good discussion of doing this sort of thing here Searching large files before browser timeout
which includes (amongst other things) a node I wrote one way to do this and also
a link to one of merlyn's columns on the same subject which covers the topic in detail.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] |
well.. if you're using system to call the script, and you're on a unix machine.. you can always make it run in the background with the shell & indicator : system("foo.pl &"); ...
-Syn0 | [reply] [d/l] |
include script B as a sub and fork - quick and dirty...
# print cgi response as usual, then...
my $pid;
if ($pid = fork) {
# display run, so exit
exit(0);
}
elsif (defined $pid) {
# run script b function if $run_script_b true...
if ($run_script_b) {
script_B();
}
}
else {
# raise an error coz the fork failed
...
}
Works for me. My script starts an FTP install that can take up to half an hour to run, depending on network connection.
cLive ;-) | [reply] [d/l] |