You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Shimon Rura <sh...@rura.org> on 2000/10/14 01:15:30 UTC

can I close the client connection but keep a script running?

I'd like to be able to tell apache to close off its connection with the
client but leave the script running.  An example use would be for the client
to start a time-consuming job on the web server, and let it run without
subjecting them to a spinning wait icon for 10 minutes.  Also, and perhaps
more importantly, I'd like to be able to run the script knowing that it
won't be interrupted if the client presses their STOP button.  Is there a
way to do this from mod_perl and/or Apache::ASP?

This feature is implemented in AOLserver API with the "ns_conn close"
command.

thanks,
shimon.

Re: can I close the client connection but keep a script running?

Posted by Gunther Birznieks <gu...@extropia.com>.
It probably depends on his situation.

If this is not happening so frequently, then wasting an apache process 
shouldn't be so bad. Writing an entire daemon plus a protocol for 
communicating to it seems excessive in some cases and adds a point of 
failure (the new daemon).

Another alternative if you don't want to waste the apache process (all you 
are really losing is a preloaded cache that is taken away for awhile), is 
to have that process launch a perl script that then disconnects itself from 
your mod_perl script so that the mod_perl script is free to continue 
running. The fact that it takes up a bit of resources on your server 
shouldn't be so bad, again, if it's an issue of an infrequent process. The 
launching of the command could also be done via SSH to another server as 
well if you are worried about the load on the main one.

At 07:46 PM 10/13/00 -0400, Neil Conway wrote:
>On Fri, Oct 13, 2000 at 07:15:30PM -0400, Shimon Rura wrote:
> > I'd like to be able to tell apache to close off its connection with the
> > client but leave the script running.  An example use would be for the 
> client
> > to start a time-consuming job on the web server, and let it run without
> > subjecting them to a spinning wait icon for 10 minutes.
>
>This has been discussed in detail by the list recently. The solution
>you describe ('closing the connection to the client') is not ideal
>because it wastes 1 Apache child, which sits idle while it waits for
>the Perl script to complete. I think the consensus was that the best
>solution is to pass the request to an external program (possibly a
>daemon) through some method (RPC, 'queue' directory or DB table, etc),
>and then let the external program perform the time consuming task,
>while the mod_perl script returns the data to the client like normal.
>
>If I've got something wrong, sorry - check one of the archives for
>extensive discussion.
>
>HTH,
>
>Neil
>
>--
>Neil Conway <ne...@home.com>
>Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc
>Encrypted mail welcomed
>
>Is uniformity [of religion] attainable? Millions of innocent men,
>women, and children, since the introduction of Christianity, have
>been burnt, tortured, fined, imprisoned; yet we have not advanced
>one inch towards uniformity.
>         -- Thomas Jefferson, "Notes on Virginia"


Re: can I close the client connection but keep a script running?

Posted by Neil Conway <nc...@klamath.dyndns.org>.
On Fri, Oct 13, 2000 at 07:15:30PM -0400, Shimon Rura wrote:
> I'd like to be able to tell apache to close off its connection with the
> client but leave the script running.  An example use would be for the client
> to start a time-consuming job on the web server, and let it run without
> subjecting them to a spinning wait icon for 10 minutes.

This has been discussed in detail by the list recently. The solution
you describe ('closing the connection to the client') is not ideal
because it wastes 1 Apache child, which sits idle while it waits for
the Perl script to complete. I think the consensus was that the best
solution is to pass the request to an external program (possibly a
daemon) through some method (RPC, 'queue' directory or DB table, etc),
and then let the external program perform the time consuming task,
while the mod_perl script returns the data to the client like normal.

If I've got something wrong, sorry - check one of the archives for
extensive discussion.

HTH,

Neil

-- 
Neil Conway <ne...@home.com>
Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc
Encrypted mail welcomed

Is uniformity [of religion] attainable? Millions of innocent men,
women, and children, since the introduction of Christianity, have
been burnt, tortured, fined, imprisoned; yet we have not advanced
one inch towards uniformity.
        -- Thomas Jefferson, "Notes on Virginia"

Re: can I close the client connection but keep a script running?

Posted by Joshua Chamas <jo...@chamas.com>.
Shimon Rura wrote:
> 
> I'd like to be able to tell apache to close off its connection with the
> client but leave the script running.  An example use would be for the client
> to start a time-consuming job on the web server, and let it run without
> subjecting them to a spinning wait icon for 10 minutes.  Also, and perhaps
> more importantly, I'd like to be able to run the script knowing that it
> won't be interrupted if the client presses their STOP button.  Is there a
> way to do this from mod_perl and/or Apache::ASP?
> 
> This feature is implemented in AOLserver API with the "ns_conn close"
> command.
> 

Try the ASP $Server->RegisterCleanup(), which is an alias 
for Apache->register_cleanup(), to execute things after output
is sent to the client.

-- Joshua