By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,722 Members | 1,874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,722 IT Pros & Developers. It's quick & easy.

Aborting HTTP connection from server-side

P: n/a
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 ]
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Jul 16 '05 #2

P: n/a
"11abacus" <ja******@hotmail.com> wrote in message
news:1a**************************@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
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.