Closing an HTTP connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    Closing an HTTP connection

    Hi,

    I need some help here.

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

    For example:

    <html>
    <body>
    This is a web page
    </body>
    </html>
    <?php
    shell_exec("pro gram");
    ?>


    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.

  • ZeldorBlat

    #2
    Re: Closing an HTTP connection

    >From http://www.php.net/manual/en/function.exec.php

    "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."

    Comment

    • ZeldorBlat

      #3
      Re: Closing an HTTP connection

      Also, the very first comment here:
      <http://www.php.net/manual/en/function.shell-exec.php> explains how to
      do this with shell_exec()

      Comment

      • Colin McKinnon

        #4
        Re: Closing an HTTP connection

        ZeldorBlat wrote:
        [color=blue][color=green]
        >>From http://www.php.net/manual/en/function.exec.php[/color]
        >
        > "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."[/color]

        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_shutdo wn_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_backgro und=`echo $name_of_script | at now`;

        Chris wrote:
        [color=blue]
        > Is it possible to close an HTTP connection in the middle of a php
        > script?[/color]

        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.

        C.

        Comment

        Working...