I have a Perl script that is activated by an end user clicking on a shortcut in a web browser. The script iterates over a list of hash values. It outputs to the browser some HTML when it inserts a row into the database for each iteration. The environment was Perl, Windows Server 2003 Standard Edition, IIS. I recently migrated to Apache. Traditionally the number of iterations has been small, and most users closed the browser after the page finished loading. Now, we have a case where there are up to 5000 iterations. Now it takes a long time (1 min~) to execute those 5000 iterations. That is not the problem. The problem is that when the user closes the web browser Apache kills the Perl script and we do not finish inserting the rows into the database because the browser doesn't acknowledge the most recently sent html. I have tested this under IIS and after the user closes the web browser, the Perl script continues to run and all the rows are inserted. Is there a setting in the Apache config file that will force Apache to finish running the Perl script even after browser is closed and the socket is dropped?

This is what we are doing:

foreach my $Destination (sort keys %{$self->{_Destinations}}) {
   print qq! <td $self->{_bgcolor}>$Destination Queued</td> !;

   if ($self->{_Data}->Execute(@params))   {&error}

I know we should do all the database inserts and THEN do our print, but this is legacy code and if I could just get Apache to behave like IIS in this regard then I will have time to do a more thorough re-write of this script.


You need to put any work that must happen even if the browser is closed / the connection is terminated in a background job. Use a work queue (I like resque, but practically anything will work) and a job processor to retrieve the jobs and do the necessary insertion. Questions about writing that code are best asked on stackoverflow.

  • This is the direction we are heading now. I know this is the correct way to do it; I was just hoping there might be a trick in Apache to hold us over until we can do the re-write. – Jason Lamoreux Jan 13 '10 at 22:53

On a Unix server, in your perl scripts you can try ignoring signals, e.g.,


This probably isn't helpful if you are running Windows servers.

On unices, this could raise other issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.