On Wed, Nov 08, 2006 at 03:38:28PM -0500, Jason Purdy wrote:
> Since I'm posting, I'll add a lil' nugget I just gleamed. We have a
> utility script that may take a while to run, so I worked in a fork()
> call, which meshes very well with cgiapp. It helps that I don't need to
> worry about the output of the script.
>
> sub my_runmode {
> my $self = shift;
> my $query = $self->query();
> $query->param( 'eid' ) =~ m%^(\d+)$%;
> my $email_id = $1;
> my $email = OTREmail->retrieve( $query->param( 'eid' ) );
Not sure if this was just typed into your email, or pasted from
actual code, but is there any reason you don't use the untainted
$email_id in your call to OTREmail->retrieve() ?
> # forking off the email sending...
> if ( my $pid = fork() ) {
> # this is the parent, in which case, we don't need anything else
> # ... Nothing to see here ...
> # ... Move along! ...
> } elsif( defined $pid ) {
> # this is the child
> close( STDOUT ); # so the parent can move on... :)
> my $output = qx%./otr_sendemails.pl $email_id%;
> } else {
> die "Cannot fork off email thread: $!";
> }
> return $self->forward( 'start' );
> }
Should the child process exit after it's done running the
external process? Its return value ($self->forward()) won't be
seen by the end user. Perhaps consider using exec() to replace the
child process with the (possibly long-running) otr_sendemails.pl
script.
A similar technique (where the user sees a "pause" page while
waiting for the background process) is described in one of Randal
Schwartz's columns:
http://www.stonehenge.com/merlyn/WebTechniques/col20.html
Make sure if you are running under mod_perl that you handle
forking as suggested in the mod_perl guide:
http://perl.apache.org/docs/1.0/guide/performance.html#Forking_and_Executing_Subprocesses_from_mod_perl
Thanks,
-E
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]