Aborting HTTP connection from server-side

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

    Aborting HTTP connection from server-side

    Hi all,

    I wonder if this is possible: I have a script that does things that
    take time. In the first part of the script it does data checking and
    other verifications, then comes the long part. I wish to be able to
    send the result of the first part to the client, disconnect the HTTP
    (so the client can do whatever they want), the script should then
    continue with the rest of the time consuming tasks, at the end of
    execution (or if an error occurs) an e-mail is sent.

    The key here is that it's the script that aborts the connection. It
    would be like putting the PHP process in the background to return the
    hand to web server, which in turn would close the connection.

    I already used the ignore_user_abo rt() to better control what's going
    on in the script.

    I've had a look at apache_child_te rminate() but it still waits that
    the PHP script ends.

    I don't want to use an HTTP refresh and for security reason I'd rather
    avoid using a system() or exec() call.

    My script is actually called by another script on another server
    (using CURL)

    I've also tried to add "Content-length: ..." in the HTTP headers and
    use flush() to force the client to read the output and close the
    connection when the byte count is reached. But it doesn't seem to work
    that well... I can't either set a too short client timeout because it
    needs to wait for the first part to be over (and it may depend on
    server load.)

    Your ideas are welcomed... of course if that could be implemented
    inside PHP itself that would be great. I don't think Apache or not
    matters...

    -Philippe
    [ 11abacus.com ]
  • Gerhard Fiedler

    #2
    Re: Aborting HTTP connection from server-side

    On 8 Sep 2003 16:50:34 -0700, 11abacus wrote:
    [color=blue]
    >I wonder if this is possible: I have a script that does things that
    >take time. In the first part of the script it does data checking and
    >other verifications, then comes the long part. I wish to be able to
    >send the result of the first part to the client, disconnect the HTTP
    >(so the client can do whatever they want), the script should then
    >continue with the rest of the time consuming tasks, at the end of
    >execution (or if an error occurs) an e-mail is sent.[/color]
    [color=blue]
    >Your ideas are welcomed... of course if that could be implemented
    >inside PHP itself that would be great. I don't think Apache or not
    >matters...[/color]

    i think the server probably matters. i can't offer any solution at
    hand, but this citation from the PHP manual (the flush() function). it
    shows that the problem you are having might not be PHP related, but
    server related.
    _______________ _______________

    Note: flush() has no effect on the buffering scheme of your webserver
    or the browser on the client side.

    Several servers, especially on Win32, will still buffer the output
    from your script until it terminates before transmitting the results
    to the browser.

    Server modules for Apache like mod_gzip may do buffering of their own
    that will cause flush() to not result in data being sent immediately
    to the client.

    Even the browser may buffer its input before displaying it. Netscape,
    for example, buffers text until it receives an end-of-line or the
    beginning of a tag, and it won't render tables until the </table> tag
    of the outermost table is seen.

    Some versions of Microsoft Internet Explorer will only start to
    display the page after they have received 256 bytes of output, so you
    may need to send extra whitespace before flushing to get those
    browsers to display the page.

    Comment

    • Andres Viikmaa

      #3
      Re: Aborting HTTP connection from server-side

      "11abacus" <jausions@hotma il.com> wrote in message
      news:1a2a8cd7.0 309081550.5044a 45a@posting.goo gle.com...[color=blue]
      > Hi all,
      >
      > The key here is that it's the script that aborts the connection. It
      > would be like putting the PHP process in the background to return the
      > hand to web server, which in turn would close the connection.
      >
      > I already used the ignore_user_abo rt() to better control what's going
      > on in the script.
      >[/color]

      Maybe you are missing this:
      -----------------------------------------------------------------
      Apache configuration options

      Name Default Changeable Function
      child_terminate Off PHP_INI_ALL specify whether PHP scripts may
      request
      child process termination on
      end of
      request, see also apache_child_te rminate()
      ----------------------------------------------------------------------------
      -

      Andres


      Comment

      Working...