SPUG: Web interface problem
Melissa D. Binde
binde at terindell.com
Thu Mar 7 15:46:00 CST 2002
You need to close both standard out and standard error after printing your
"this job is being processed message":
close(STDOUT);
close(STDERR);
that tells the web server that it's okay to continue.
Then fork twice to disassociate yourself from the parent process and set
yourself up as the leader of a new process group:
if (!defined($pid = fork)) {
&error_and_exit ("Unable to fork: $!\n");
} elsif ($pid) {
waitpid ($pid, 0);
exit 0;
}
#
# child. fork again.
#
if (!defined($pid = fork)) {
&error_and_exit ("Unable to fork: $!\n");
exit 1;
} elsif ($pid) {
exit 0;
}
&POSIX::setsid();
My script can also be run from the command line (it behaves "correctly"
based on whether it's being called in a CGI context or not), so the double
forking and new process group may not be required for a web solution, I
don't know. I'm sure someone here can answer, though.
The resulting disassociated process then emails the user when it's done.
Conversely, you can use a page that refreshes (simply the parent, in the
first fork there) to show current status to the user ("Yes/No" for
completion.)
Twas brillig, on Wed Mar 06 at 11:26:49 AM, and Daryn Nakhuda burbled:
>
> I'd love to hear a good way to do this as well.. Fork seemed to keep the
> little globe spinning in IE, but maybe I was doing it wrong. My hack to
> make it seem okay to the end user was just to schedule an at job (+10
> seconds) from the cgi, then tell them it was being processed. I then had
> another place where you could check the status of jobs (the script being
> run by at updated the database as it ran).
>
>
>
> On Wed, 6 Mar 2002, Mikel Tidwell wrote:
>
> > Hi everyone,
> >
> > I'm stumped on how to proceed on a page for a web interface I'm creating
> > for my web site. I want to be able to download a typically large file off
> > another web server, and store it on the local server. By large, I mean an
> > average of 20 MB or so, but up to 100 MB at a typical rate of 30K/s.
> >
> > Here's how I expect it to work:
> >
> > * User locates the file on another site, comes to the interface, and
> > commands the file be downloaded.
> > * Script uses either LWP or `wget` to fetch file. <Problem>
> > * Script moves on to allow the person how to name the file, etc.
> >
> > Problem: Downloading a file usually takes more than two minutes. If the
> > client doesn't time out by then, the web server will terminate the process
> > anyway (cgi time limit in Roxen). I could simply change this limit, but
> > I'm looking for a smarter solution.
> >
> > I thought about creating a child process, but I know very little about
> > fork(), or what happens to the parent in this scenario. I also have an
> > issue with, should the child be able to download the file, notifying the
> > user that the download was complete, so he/she can continue.
> >
> > If this still makes any sense, please help. Thanks... ^^
> >
> > _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _
> > -- Mikel Tidwell President: RPGamer -- http://www.rpgamer.com/
> > MSNM: FireMyst Personal Home Page -- http://dragon.rpgamer.com/
> > - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ - _ -
> >
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> > Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> > Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> > For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> > Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
> >
> >
>
> --
>
>
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
>
>
-M.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list