tags:

views:

237

answers:

5

Hello,

I am not completely sure that this is possible from within PHP or even the HTTP protocol in depth. Is it possible to receive PHP script to run when it is requested but then the script drops the connection? Without replying?

Hopefully my question makes sense.

(I am using Apache)

+3  A: 

You can use exit() or die() in the script to stop script execution, would that do what you want?

Phill Sacre
Will that cause a HTTP reply?
Improfane
I would like it to simply not reply, to time out by forgetting about the connection. Sleeping doesn't really do this because it is still 'around' but for later.
Improfane
+1  A: 

Why would you want to do this? Surely you should be sending some kind of HTTP error code instead?

Tim Wardle
A: 

That depends on the software you use. Apache for example terminates any scripts as soon as the connection closes.

Georg
A: 

If you don't want to send any data at all, use a sleep in a loop. Eventually the client end will time out and close the connection.

Ant P.
+6  A: 

When you serve php through Apache, there will always be a http response. Calling exit will just stop php from processing - not stop Apache. The proper thing to do in your case, is probably to send a http response-code other than 200 (OK). For example 404 or 500. Check the specs to find the one that applies to your situation.

You send a http response from within php, using:

<?php
  header("HTTP/1.0 404 Not Found");
  exit;
troelskn