On Tue, 6 Jun 2000, Jeremy Howard wrote:

> Jie Gao said (talking about avoiding memory problems with
> libareq::parms()):
> > What I do is kill the child process after uploading is finished:
> >
> >     $r->child_terminate();
> >
> > Not an elegant way, but it works for the time being.
> 
> Good idea. I've implemented something which uses this approach if the
> file upload size is 'too big'. Here's the code I use--I hope someone else
> finds it useful:
> 
> use constant MAX_SIZE_KILLPROC => 2000000;
> my $TotalSize = 0;
> foreach my $ThisAtt ($R->upload()) {
>   # Check that filehandle for uploaded file is valid
>   if ($ThisAtt->fh) {
>     SaveAtt ($MsgId, $ThisAtt)
> ### Replace next line with your own error handler
>       || return $Self->SignalError(ERR_UPLOAD_FAILED);
>     $TotalSize += $ThisAtt->size();
>   } # If valid fh
> 
>   # Work around bug in libareq->parms, that uses up too much memory
>   $R->post_connection(sub {$R->child_terminate()})
>     if $TotalSize > MAX_SIZE_KILLPROC;
> }

you don't need:
>   $R->post_connection(sub {$R->child_terminate()})

this is just right:
    $R->child_terminate()

It doesn't look like the right name was chosen, but what it does is
setting the internal value of MaxRequestsPerChild to 1, so when the
request is over the child gets killed by the parent based on this standard
feature. A nice thing IMHO.

So child_terminate() won't terminate the child right away...

But regarding all these suggested workarounds, why reinvent the wheel,
Apache::SizeLimit and Apache::GTopLimit do that already.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org

Reply via email to