Closing an HTTP connection

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need some help here.

Is it possible to close an HTTP connection in the middle of a php

For example:

This is a web page

I know that the shell_exec statement will take a long time to complete.
But I also know that no further content needs to be delivered to the
user. Is it possible to close the connection so that the browser is not
hanging around waiting for more information, but the php script keeps
running on the server?

Thanks for any help.

Re: Closing an HTTP connection

Quoted text here. Click to load it

"Note: If you start a program using this function and want to leave it
running in the background, you have to make sure that the output of
that program is redirected to a file or some other output stream or
else PHP will hang until the execution of the program ends."

Re: Closing an HTTP connection

ZeldorBlat wrote:

Quoted text here. Click to load it

Won't work - you haven't dissocciated the new process from the parent.
(Might work on a non-unix system). The webserver won't send an EOF until
the chid process terminates. You could call it from a function registered
using register_shutdown_function() to run after the socket is closed but
that's still messy as the the webserver process hangs around to wait for it
to exit.

You can create a separate process group easily using the 'at' command.

$run_in_background=`echo $name_of_script | at now`;

Chris wrote:
Quoted text here. Click to load it

If the above didn't answer your question (there are instances where you
might want to disconnect from the browser but continue with the current
thread of execution) then repost - there's an answer to this as well, but
it really starts getting complicated and you need to start working with
proxy scripts and sockets.


Re: Closing an HTTP connection

Also, the very first comment here:
< explains how to
do this with shell_exec()

Site Timeline