Aborting HTTP connection from server-side

This is a discussion on Aborting HTTP connection from server-side within the PHP Language forums, part of the PHP Programming Forums category; Hi all, I wonder if this is possible: I have a script that does things that take time. In the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-09-2003
11abacus
 
Posts: n/a
Default 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_abort() to better control what's going
on in the script.

I've had a look at apache_child_terminate() 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 ]
Reply With Quote
  #2 (permalink)  
Old 09-09-2003
Gerhard Fiedler
 
Posts: n/a
Default Re: Aborting HTTP connection from server-side

On 8 Sep 2003 16:50:34 -0700, 11abacus wrote:

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


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


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.

Reply With Quote
  #3 (permalink)  
Old 09-09-2003
Andres Viikmaa
 
Posts: n/a
Default Re: Aborting HTTP connection from server-side

"11abacus" <jausions@hotmail.com> wrote in message
news:1a2a8cd7.0309081550.5044a45a@posting.google.c om...
> 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_abort() to better control what's going
> on in the script.
>


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_terminate()
----------------------------------------------------------------------------
-

Andres


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0